swagger-api / swagger-api/swagger-ui

Unrecognized response type; displaying content as text.

Open
#10,128 1 comment 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
  • Browser: chrome
  • Version: 128
  • Method of installation: npm
  • Swagger-UI version: 5.17.14
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Swagger/OpenAPI definition:

{
  "downloadFile": {
    "get": {
      "tags": [
        "Download Data File"
      ],
      "summary": "Get Download File",
      "operationId": "v1_download_data_file",
      "produces": [
        "application/zip"
      ],
      "parameters": [
        {
          "name": "Content-Type",
          "in": "header",
          "required": true,
          "schema": {
            "type": "string",
            "example": "application/json"
          }
        },
        {
          "name": "Accept",
          "in": "header",
          "required": true,
          "schema": {
            "type": "string",
            "example": "application/zip"
          }
        },
        {
          "required": true,
          "schema": {
            "type": "string",
            "example": "54e72396-57ed-4d35-9066-b3b3b58b0b06"
          },
          "name": "attachment-id",
          "in": "path"
        }
      ],
      "responses": {
        "200": {
          "description": "Successful Response",
          "headers": {
            "Content-Encoding": {
              "name": "Content-Encoding",
              "description": "A Encoding Algorithm used for encoding response",
              "in": "header",
              "schema": {
                "type": "string"
              }
            },
            "Content-Disposition": {
              "name": "Content-Disposition",
              "in": "header",
              "schema": {
                "type": "string"
              }
            }
          },
          "content": {
            "application/zip": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "400": {
          "description": "Failure Response",
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "403": {
          "description": "Authorization information is missing or invalid.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        }
      }
    }
  }
}

Swagger-UI configuration options:

SwaggerUI({
  dom_id: '#swaggerUIApp',
      url: this.state.doc,
      deepLinking: true,
})
How can we help?

Hello,

I am hitting one api which gives zip file as response with Content-Disposition, Content-Type response headers. When I am trying to hit that api from postman, I will get the file response and I can download the zip file but in swagger, I am receiving the file response as text with Unrecognized response type; displaying content as text. this error and it is downloaded as text file when I am trying to download it.

Here I pasted the json config file of that swagger route.

I am receiving following response headers values.

  1. Content-Disposition :- attachment; filename=output.zip
  2. Content-Type :- application/zip

So can anyone help to figure it out.

Screenshot from 2024-09-10 13-02-27

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

No source file or test is named. Reproduce the issue with the supplied OpenAPI response definition and SwaggerUI configuration, then inspect Swagger UI's response handling for application/zip and application/octet-stream. Done means the binary response with Content-Disposition is treated as a downloadable zip rather than displayed or downloaded as text.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.