Skip to content

Overriding SWAGGER_JSON and URL does not work for Docker distribution #5213

@sgwood63

Description

@sgwood63

Context

  • OS: Alpine (Docker)
  • Browser: any
  • Method of installation: Docker
  • Swagger-UI version: 3.20.X and 3.21.X at least
  • Swagger/OpenAPI version: any

SWAGGER_JSON environment variable ignored by Docker deployment

The Docker build of swaggerapi/swagger-ui does not work when overriding the SWAGGER_JSON with a mounted file as documented in https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md.

run.sh updates the nginx index.html if a mounted file $SWAGGER_JSON exists.

if [[ -f $SWAGGER_JSON ]]; then
  cp -s $SWAGGER_JSON $NGINX_ROOT
  REL_PATH="./$(basename $SWAGGER_JSON)"
  sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
  sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE
fi

Problem is that the base image used by swaggerapi/swagger-ui - FROM nginx:1.15-alpine - has a index.html.gz file which takes precedence over the index.html, so the updated index.html is ignored.

To reproduce:

Have your swagger.json in /bar

docker pull swaggerapi/swagger-ui
docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui

Access swagger-ui @ http:///

Will see petstore, not your swagger.json.

URL environment variable ignored by Docker deployment

To reproduce:

Have your swagger.json in http:///swagger.json

docker pull swaggerapi/swagger-ui
docker run -p 80:8080 -e URL="http:///swagger.json" swaggerapi/swagger-ui

Access swagger-ui @ http:///

Will see petstore, not http:///swagger.json.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions