swagger-api / swagger-api/swagger-ui

Arrays are sent incorrectly in `multipart/form-data`

Open
#10,221 3 comments 6 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 11
  • Browser: Firefox
  • Version: 130
  • Method of installation: npm
  • Swagger-UI version: 5.18.2
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.1
info:
  title: DotNet9WebApi
  version: '1.0'
paths:
  /WeatherForecast/post:
    post:
      tags:
        - DotNet9WebApi
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/PostBody'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/PostBody'
      responses:
        '200':
          description: OK
components:
  schemas:
    PostBody:
      type: object
      properties:
        content:
          type: string
          nullable: true
        intArrProp:
          type: array
          items:
            type: integer
            format: int32
          nullable: true
      additionalProperties: false
Describe the bug you're encountering

When submitting an array as multipart/form-data content, the values are sent as a comma-separated list, instead of as multiple form parts with the same name.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io/
  2. Paste the above sample YAML into the editor
  3. Try out the /WeatherForecast/post endpoint
  4. Add 2 or more items into the intArrProp array using the Add integer item button
  5. Click Execute and observe the resulting curl
Expected behavior

The curl should look like this:

curl -X 'POST' \
  'https://editor-next.swagger.io/WeatherForecast/post' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'content=string' \
  -F 'intArrProp=1' \
  -F 'intArrProp=2' \
  -F 'intArrProp=3'
Actual behavior

The curl looks like this:

curl -X 'POST' \
  'https://editor-next.swagger.io/WeatherForecast/post' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'content=string' \
  -F 'intArrProp=1,2,3'
Screenshots

image

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 request in editor-next.swagger.io with the supplied OpenAPI 3.0.1 definition and inspect the multipart/form-data request generation. Done means the generated curl sends each intArrProp value as a separate repeated -F form part rather than one comma-separated value.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.