Skip to content

Docker swagger-ui container HTTP caching #5144

@segevfiner

Description

@segevfiner

Q&A (please complete the following information)

  • OS: macOS 10.14.3
  • Browser: Firefox
  • Version: 64.0.2
  • Method of installation: Docker
  • Swagger-UI version: v3.20.5
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

$ docker run --rm -p 8888:8080 -e SWAGGER_JSON=/openapi.yaml -v $PWD/openapi.yaml:/openapi.yaml swaggerapi/swagger-ui

Describe the bug you're encountering

swagger-ui doesn't update on refresh after changing the openapi.yaml file outside the container. Displaying the old version of the OpenAPI document instead.

To reproduce...

Steps to reproduce the behavior:

  1. Start the swagger-ui Docker container with some openapi.yaml file.
    $ docker run --rm -p 8888:8080 -e SWAGGER_JSON=/openapi.yaml -v $PWD/openapi.yaml:/openapi.yaml swaggerapi/swagger-ui
  2. Open swagger-ui in the browser.
  3. Modify the openapi.yaml in some way.
  4. Refresh the browser.
  5. The changes don't appear after refresh.

Expected behavior

The changes appear after refresh.

Additional context or thoughts

This is caused due to not specifying caching headers in the Nginx configuration. Simply adding an expires -1 to the configuration will resolve this, though it will make the browser re-validate the static swagger-ui files on each request. Without these headers the browsers use an unspecified heuristic caching behavior.

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