swagger-api / swagger-api/swagger-ui

Not able to decode multipart response

Open
#5,293 6 comments 11 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: Windows
  • Browser: Chrome
  • Version: 73.
  • Method of installation: npm
  • Swagger-UI version: Latest
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Fails to decode the response when it is of multipart type.

Example Swagger/OpenAPI definition:

# your YAML here
  /xyz:
    post:
      parameters:
        - in: query
          name: q
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                upfile:
                  type: string
                  format: binary
                params:
                  type: string
      responses:
        '200':
          description: OK
          content:
            multipart/form-data:
              schema:
                type: object
                properties:
                  points:
                    type: string
                  file:
                    type: string
                    format: binary
              encoding:
                points:
                  contentType: text/plain
                file:
                  contentType: application/octet-stream
Describe the bug you're encountering

When the UI receives the response from the server where the response has multipart body, the UI doesn't decode the message and displays the result accordingly.

Currently it shows the following error and tries to display everything as text (even the binary junk characters) and the multipart data is not split into corresponding part files.

Response body
Unrecognized response type; displaying content as text.

--29c81d996c8947829f47f91a3c36aa4f
Content-Disposition: form-data; name="points"

[1,2,3,4,5]
--29c81d996c8947829f47f91a3c36aa4f
Content-Disposition: form-data; name="file"; filename="tmp1e95kj4w.nii.gz"
Content-Type: application/octet-stream

��8�\�tmp1e95kj4w.nii��$��V��0?�  7������~��08u���JI))�ʔV�8���T�[Kս�̙�����G����Ͽ����������w�������������?����5����o�5�x������/O���_���?��ϟ���?}
Expected behavior
  1. binary data part as downloadable link
  2. text/plain data part on UI screen

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 OpenAPI 3.0 example in Swagger UI and inspect the response handling for multipart/form-data. Use the shown multipart response, including its text/plain and binary parts, as the test case; done means text is rendered in the UI and binary data is exposed as a downloadable link without displaying binary junk.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.