swagger-api / swagger-api/swagger-ui

"Download file" for HTTP code 400 do not download the file correctly

Open
#7,952 0 comments 5 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

  • OS: Windows 10
  • Browser: Firefox (also same in latest Chrome)
  • Version: 98
  • Method of installation: NuGet
  • Swagger-UI version: 4.5.0
  • Swagger/OpenAPI version: Swagger 2.0, OpenAPI 3.0.1

When I return a file with a code 200 I'm presented with "Download file" which will download the provided file, but if I change the return code to 400 I will still get the "Download file" option but it wont use the file provided in the response body. Instead I will get a file which only contains the text "OrderedMap {}". I can observe in the network traffic that the correct file is sent, and that no other parameters in the response have changed except for the status code.

Steps to reproduce the behavior:

  1. Make a request to an endpoint which returns a file with a status 400 code, in my case producing:
HTTP/1.1 400 Bad Request
Content-Length: 3877
Content-Type: application/octet-stream
Date: Mon, 28 Mar 2022 13:44:54 GMT
Server: Kestrel
Content-Disposition: attachment; filename=string.xlsx; filename*=UTF-8''string.xlsx
  1. Click "Download file".
Expected behavior

The file which was sent in the request body is downloaded.

Additional context or thoughts

I'd guess there currently exist some logic which either special handle 200 OK response to give correct file or 400 Bad request to be a specific format?

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 by reproducing the Swagger UI "Download file" behavior with a 400 response carrying the shown application/octet-stream headers, and compare it with the 200 response in the network traffic. Trace the response handling that produces the download and verify that the downloaded content matches the response body rather than "OrderedMap {}".

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
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.