swagger-api / swagger-api/swagger-ui
Multipart request doc example for OpenAPI 3.0 fails with err "not of type 'object' - 'address'"
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Using Python3.8, flask 1.1.4, connexion 2.9.0 and swagger-ui-bundle 0.0.9 I cannot make the example work from https://swagger.io/docs/specification/describing-request-body/multipart-requests/ and I pasted that spec below. Please forgive if this is a dupe, I searched other open issues for multipart but didn't spot an exact match to this behavior.
Q&A (please complete the following information)
- OS: macOS
- Browser: Firefox
- Version: 91.1.0
- Method of installation: Python pip3, virtual environment
- Swagger-UI version: OAS3 (where is the exact version shown?)
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Example Swagger/OpenAPI definition -- exactly the spec from the Swagger web site, URL above
requestBody:
content:
multipart/form-data: # Media type
schema: # Request payload
type: object
properties: # Request parts
id: # Part 1 (string value)
type: string
format: uuid
address: # Part2 (object)
type: object
properties:
street:
type: string
city:
type: string
profileImage: # Part 3 (an image)
type: string
format: binary
Swagger-UI configuration options: (none)
Describe the bug you're encountering
The multipart form is not uploaded as I expect. I click "Try it out" in the UI, put in valid data. The window shows this cURL command:
curl -X 'POST' \
'http://localhost:5000/api/v1/request_file' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'address={
"city": "string",
"street": "string"
}' \
-F 'id=abc' \
-F 'profileImage=@my-req-1.txt;type=text/plain'
But an error comes back:
{
"detail": "'{\\r\\n \"city\": \"string\",\\r\\n \"street\": \"string\"\\r\\n}' is not of type 'object' - 'address'",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}
The server logs this error:
2021-10-18T15:10:06-0400 ERROR connexion.decorators.validation http://localhost:5000/api/v1/request_file validation error: '{\r\n "city": "string",\r\n "street": "string"\r\n}' is not of type 'object' - 'address'
To reproduce...
Steps to reproduce the behavior:
- Start the server
- Go to the endpoint with this content model
- Click on Try it out
- Browse to a file for upload; leave the suggested string-parameter values
- Click execute
- See the error in the response window area
Expected behavior
I was hoping the documentation example would work :)
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 at Swagger UI's Try it out form and reproduce the issue with the OpenAPI 3.0 multipart schema from the linked documentation example. Compare the generated cURL request and the server's validation error for the nested address field. Done means the documented multipart example submits successfully without the address type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100