Arrays are sent incorrectly in `multipart/form-data`
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:
- Go to https://editor-next.swagger.io/
- Paste the above sample YAML into the editor
- Try out the
/WeatherForecast/postendpoint - Add 2 or more items into the
intArrProparray using theAdd integer itembutton - Click
Executeand observe the resultingcurl
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
Same issue. It seems that switching to Swagger 2 (OpenAPI 2) fixes this.
Hello there! You can specify the formatting of given property values by using an encoding object. In this specific scenario, the schema should look like this:
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'
encoding:
intArrProp:
explode: true
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
ref: https://swagger.io/specification/#media-type-object
https://github.com/swagger-api/swagger-ui/issues/3494#issuecomment-3379154976
this worked as well.