swagger-api / swagger-api/swagger-ui
Fix the Issue: multipart/form-data with Nested Objects
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Content & configuration
Swagger/OpenAPI definition:
openapi: 3.0.0
paths:
/api/test:
post:
operationId: TestController_test
parameters: []
requestBody:
required: true
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/TestDto'
application/json:
schema:
$ref: '#/components/schemas/TestDto'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/TestDto'
responses:
'201':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/TestDto'
info:
title: TESTAPI
description: Routes description for test API
version: '1.0'
contact: {}
tags: []
servers: []
components:
securitySchemes:
bearer:
scheme: bearer
bearerFormat: JWT
type: http
schemas:
BarDto:
type: object
properties:
bar:
type: string
required:
- bar
FooDto:
type: object
properties:
foo:
type: string
bar:
$ref: '#/components/schemas/BarDto'
required:
- foo
- bar
TestDto:
type: object
properties:
test:
type: string
foo:
$ref: '#/components/schemas/FooDto'
required:
- test
- foo
Is your feature request related to a problem?
When I attempt to send a multipart/form-request, it sends the nested object as string (JSON) instead of form-data. For example, when swagger describe the request using cURL, I encounter the following issue.
curl -X 'POST' \
'http://localhost:3000/api/test' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'test=test' \
-F 'foo={
"foo": "string",
"bar": {
"bar": "string"
}
}'
Describe the solution you'd like
I'd like to format the nested object in multipart/form-data as shown in this cURL request.
curl -X 'POST' \
'http://localhost:3000/api/test' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'test=test' \
-F 'foo[foo]=string' \
-F 'foo[bar][bar]=string'
Describe alternatives you've considered
If the request is multipart/form-data and the data is in object format, we can format the nested object as follows.
Additional context
I believe there might be an issue. When I create an API and attempt to use multipart/form-data, the typical way to send data with tools like Postman or via Fetch/Axios involves a structure like 'foo[foo]...'. However, Swagger sends it in string (JSON) format, which doesn't work correctly in my application. I think it should be sent in the former format.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied OpenAPI definition in Swagger UI and inspect the generated multipart/form-data cURL request. The change is complete when nested objects are emitted with bracketed field names such as foo[foo] and foo[bar][bar], rather than as a JSON string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100