question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker deployments: add support for the URL environment variable

See original GitHub issue

Content & 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
char0ncommented, Feb 3, 2022

Sure, go ahead!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variables in Compose | Docker Documentation
Substitute environment variables in Compose files. If you have multiple environment variables, you can substitute them by adding them to a default environment...
Read more >
How to Set Docker Environment Variables {ARG and ENV}
Set Docker environment variables in a Dockerfile, and override them using Docker CLI and Docker Compose by following this easy tutorial.
Read more >
Docker Environment Variables: Setup and Configuration for ...
Docker allows developers to set and manage environment variables in the command line interface (CLI) or an external file (. ENV). Here are...
Read more >
Making environment variables accessible in front-end containers
Learn how to inject environment variables directly into your React, Angular, or Vue.js codebase during the front-end container build ...
Read more >
Set Environment-Specific Configuration with Docker
You can also set the environment variables by passing parameters to the docker run command: docker run -e REPO_PATH='/usr/local/tomcat/repo' -e ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found