swagger-api / swagger-api/swagger-ui

swagger ui adds extra quotes when form submitted as multipart/form-data

Open
#4,146 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 2
Which Swagger-UI version? 3.9.2
How did you install Swagger-UI?
Which browser & version?
Which operating system?
Demonstration API definition
swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
host: 'localhost'
paths:
  /user/register:
    post:
      consumes:
        - "multipart/form-data"
      parameters:
        - in: "formData"
          name: "username"
          required: false
          type: "string"
          allowEmptyValue: false
        - in: "formData"
          name: "image"
          description: "User image"
          required: false
          type: "file"
        - in: "formData"
          name: "gender"
          description: "Gender: {male: 1, female: 2}"
          required: false
          items:  
            type: "string"
            allowEmptyValue: false
            enum:
              - "2"
              - "1"
          type: "array"
          allowEmptyValue: false

When I submit this form I see this curl command below response section:

curl -X POST "http://localhost/user/register" -H  "accept: application/json" -H  "Content-Type: multipart/form-data" -F "username=john" -F "gender="2""

Please note "gender="2"" <- extra quotes here

On the backend side submitted form always invalid because these extra quotes. If I change consumes to application/x-www-form-urlencoded then everything is fine but I can not upload image in that case.

What do I do wrong?

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

Reproduce the issue in Swagger UI 3.9.2 using the provided Swagger 2.0 definition and multipart/form-data submission. Start by tracing how the form parameters are serialized into the displayed curl command. Done means the gender value is emitted without extra quotes while file upload continues to work, with a regression test covering the case.

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.