swagger-api / swagger-api/swagger-ui
Inconsistent curl generated for array of objects in multipart/form-data request
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Hi,
Curl command generated for a request with multipart/form-data is inconsistent/mixed.
Having array of objects as form field in multipart/form-data request. Each array object is JSON object.
First element is properly presented in curl command without stringify operation applied.
Any array object added as result of "Add object item" button is stringified and ends as string, not an object.
Issue spotted when working on project using Python 3.8, Connexion 2.9.0, swagger-ui bundle 0.0.9 but can be reproduced on editor.swagger.io as well.
Q&A (please complete the following information)
- OS: ubuntu linux/windows
- Browser: firefox 93, Chrome Version 95.0.4638.54
- Method of installation: swagger-ui-bundle python object, editor.swagger.io
- Swagger-UI version: 3.52.0 (swagger-ui bundle 0.0.9)
- Swagger/OpenAPI version: OpenAPI 3.0.1
Content & configuration
Given below example Swagger/OpenAPI definition:
paths:
/foo:
post:
tags:
- foo
summary: bar
operationId: foo
requestBody:
description: ""
content:
multipart/form-data:
schema:
type: object
description: "zzz"
properties:
property1:
type: string
description: "property of type string, holding kind of version"
example: "1.0"
default: "1.0"
nullable: false
enum:
- "1.0"
property2:
type: array
description: array of objects
items:
type: object
description: ""
properties:
aID:
type: string
aName:
type: string
aVersion:
type: string
aLink:
type: string
example:
aID: "value aID"
aName: "value aName"
aVersion: "value aVersion"
aLink: "value aLink"
required:
- aID
- aName
- aVersion
- aLink
property3:
type: integer
format: int32
description: "property of type integer"
nullable: true
property4:
type: string
description: "yet another property of type string"
example: cow
default: cow
nullable: false
enum:
- cow
- dog
required:
- property1
- property2
encoding:
property1:
contentType: text/plain
property2:
contentType: application/json
property3:
contentType: text/plain
property4:
contentType: text/plain
responses:
200:
description: OK
content: {}
Swagger-UI configuration options: None
Describe the bug you're encountering
Produced curl command from editor.swagger.io is as follows:
curl -X 'POST' \
'https://petstore.swagger.io/v2/foo' \
-H 'accept: */*' \
-H 'Content-Type: multipart/form-data' \
-F 'property1=1.0' \
-F 'property2=[{"aID":"value aID","aName":"value aName","aVersion":"value aVersion","aLink":"value aLink"},"{\n \"aID\": \"value aID\",\n \"aName\": \"value aName\",\n \"aVersion\": \"value aVersion\",\n \"aLink\": \"value aLink\"\n}"]' \
-F 'property3=1234' \
-F 'property4=cow'
property2 is the array where first element is true JSON object, but second one is plain string and not object according to schema.
In case of input validation to the API specification as is in Connexion framework the second of stringified JSON object does not pass the JSON schema validation and request is rejected.
To reproduce...
Steps to reproduce the behavior:
- Go to editor.swagger.io
- Add path with definition from example
- Navigate to endpoint in rendered swagger-ui page
- Select path foo
- Click 'try it out'
- Under property2 add array object element with button 'Add object item'
- Click Execute
- Observe generated curl command
Expected behavior
Expected curl for array of objects shall be like first element, without stringified contents of elements added with 'Add object item'
curl -X 'POST' \
'https://petstore.swagger.io/v2/foo' \
-H 'accept: */*' \
-H 'Content-Type: multipart/form-data' \
-F 'property1=1.0' \
-F 'property2=[{"aID":"value aID","aName":"value aName","aVersion":"value aVersion","aLink":"value aLink"}, {"aID":"value aID","aName":"value aName","aVersion":"value aVersion","aLink":"value aLink"}]' \
-F 'property3=1234' \
-F 'property4=cow'
Screenshots
Additional context or thoughts
Generated curl does not respect the supplied encoding in request body by not specifying the form fields with ';type='
Proper curl coding of array of JSON objects would be:
-F 'property2=[{"aID":"value aID","aName":"value aName","aVersion":"value aVersion","aLink":"value aLink"}, {"aID":"value aID","aName":"value aName","aVersion":"value aVersion","aLink":"value aLink"}];type=application/json' \
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
Reproduce the request in editor.swagger.io using the supplied OpenAPI definition, then trace the multipart/form-data request serialization and generated curl output. Done means every array item remains a JSON object and the generated form field respects the declared application/json encoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100