Docker deployments: add support for the URL environment variable
See original GitHub issueContent & configuration
Perform a Docker deployment of the swagger-editor image with the following options:
docker run -e URL="https://petstore3.swagger.io/api/v3/openapi.json" -d -p 9999:8080 swaggerapi/swagger-editor
Then, simply browse to http://localhost:9999 and check the “home” API document loaded by default (Swagger Petstore).
Is your feature request related to a problem?
Yes. With current Docker image, swagger-editor ignores the URL
environment variable and always provide the same default API document on startup.
Describe the solution you’d like
Some swagger-ui environment variables are already supported by swagger-editor (e.g., BASE_URL
, QUERY_CONFIG_ENABLED
, etc.) .
I would like to propose a PR to support the URL
environment variable, in line with swagger-ui configuration/reference (see below).
For the users who deploy swagger-editor with Docker, this change would allow them to replace the default API document to be loaded on startup with an URL (see after for a discussion on the LocalStorage
plugin).
Describe alternatives you’ve considered
An alternative exists but it lacks of flexibility and allows the users to override configuration parameters via URL search params themselves.
In this alternative, the swagger-editor image has to be deployed with the QUERY_CONFIG_ENABLED
environment variable:
docker run -e QUERY_CONFIG_ENABLED="true" -d -p 9999:8080 swaggerapi/swagger-editor
Then, the homepage would be: http://localhost:9999/?url=https://petstore3.swagger.io/api/v3/openapi.json
However, if we then want to display another API document on startup, we are forced to update the link to be shared, with the risk that some users could still land on the “old” API document/homepage.
Additional context
I already investigated a bit the changes to be done. The following files would require some changes:
docker-run.sh
index.html
README.md
(documentation)LocalStorage
plugin (see below)
Some changes could be required for the LocalStorage
plugin so that it does not first load the Swagger Petstore default document when the URL
environment variable is specified by the user (to remove the “blinking” effet).
I have a first PoC working on my swagger-editor fork. However, because I first wanted to make something simple, I didn’t change the logic of the LocalStorage
plugin yet. Of course, I could continue to work on it if you think that it makes sense.
Swagger-UI documentation for reference and alignement:
Method name | Docker variable | Description |
---|---|---|
url |
URL |
String . The URL pointing to API definition (normally swagger.json or swagger.yaml ). Will be ignored if urls or spec is used. |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Released as https://github.com/swagger-api/swagger-editor/releases/tag/v4.1.1
Sure, go ahead!