I have a static openapi.yaml
file which looks something like this:
Existing Yaml:
openapi: 3.0.0
info:
title: API
description: >-
Awesome API
contact:
name: bh4r4th
email: nenethopu@gmail.com
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 2.0.0
servers:
- url: http://localhost:8080
description: Dev Server
- url: http://www.example.com
description: Prod Server
Now,
I wanted to pass servers
dynamically using an environment variable.
Expected Yaml:
openapi: 3.0.0
info:
title: API
description: >-
Awesome API
contact:
name: bh4r4th
email: nenethopu@gmail.com
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 2.0.0
servers: ${SWAGGER_API_URLS}
Why I wanted to do this?
- I am building my application as docker image and using same image for 100 different clients.
- So, each client has their own set of
Dev
&Prod
servers.
I tried:
- Setting
@OpenAPIDefinition
on application - Adding Beans like
OpenApiCustomizer
,OpenApi
,GlobalOpenApiCustomizer
None worked.
Before I go hacky and edit actual file on docker build. I am looking for any simple solution out of the box saves tonnes of extra configuration.
Dependencies used:
* springdoc-openapi-ui: 1.6.11
* swagger-ui: 4.14.0
* spring-boot: 2.6.6
* maven: 3.8.1