swagger-api / swagger-api/swagger-ui

Missing type:object in multipart causes example to be in json, not file uploads

Open
#4,625 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: try-it-out type: enhancement
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • Swagger-UI version: "3.17.0"
  • Swagger/OpenAPI version: OAS 3
Content & configuration

See: http://editor.swagger.io/?url=https://gist.githubusercontent.com/ponelat/eed475786cabcad61e861509c926967d/raw/ff02d25ddfe5080ddaea98189f0d28e37f4554e2/without-type-object.yaml

ie: a mutlipart/form object, that doesn't include type: object

post:
      summary: Create an item
      requestBody:
        content:
          multipart/form-data:
            schema:
              # type: object # <-- makes it work
              properties: # Request parts should NOT be rendered as JSON
                image:
                  type: string
                  format: binary
Describe the bug you're encountering

The body component creates a json example instead of a list of file upload buttons

To reproduce...
Steps to reproduce the behavior:

View a spec as above.

Expected behavior

Try it out form renders with file upload parameters

Screenshots

Actual
image
Expected
image

Fix/Notes

Bam: https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/oas3/components/request-body.jsx#L32
Doesn't use inference (ie: if properties, then its an object )
Aternatively ( outside issue ) we make this a validation error.

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 in src/core/plugins/oas3/components/request-body.jsx at the referenced line and reproduce the behavior with the linked multipart/form-data example. The change is done when a schema with properties but no explicit type: object renders file upload controls in the Try it out form instead of a JSON example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.