swagger-api / swagger-api/swagger-ui

Docker image doesn't set charset in Content-Type

Open
#10,082 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: Linux Mint 21.3
  • Browser: chrome, curl
  • Version: 126.0.6478.126, 7.81.0
  • Method of installation: docker pull
  • Swagger-UI version: latest
  • Swagger/OpenAPI version: latest
Content & configuration
Describe the bug you're encountering

Trying to use the docker image from https://hub.docker.com/r/swaggerapi/swagger-ui may fail because the internal nginx server is not configured to add charset: utf-8 to the Content-Type header. As a result, HTML that doesn't specify the charset (eg, <script src="localhost:8081/swagger-ui-bundle.js"></script>) will fail because the browser fetches swagger JS files but won't use them because of the embedded UTF characters.

To reproduce...
$ cat > docker-compose.yaml <<EOF
services:
  swagger-ui:
    image: swaggerapi/swagger-ui
    ports:
      - "8081:8080"
EOF
$ docker compose up -d
$ curl -s -D - -o /dev/null localhost:8081/swagger-ui-bundle.js | grep Content-Type:
Content-Type: application/javascript
Expected behavior

I expect that the Content-Type header includes charset=utf-8.

$ curl -s -D - -o /dev/null localhost:8081/swagger-ui-bundle.js | grep Content-Type:
Content-Type: application/javascript; charset=utf-8
Screenshots
Additional context or thoughts

This is more of a FYI for others in the future who are scratching their heads over why a simple swagger install doesn't seem to work. If that's you, add charset="UTF-8" to your <script> tag.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the docker-compose.yaml reproduction and inspect the Docker image's internal nginx configuration. Verify the response with the provided curl command; done means the JavaScript Content-Type includes charset=utf-8.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, nginx
Domain
devops, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.