swagger-ui
swagger-ui copied to clipboard
Multipart request doc example for OpenAPI 3.0 fails with err "not of type 'object' - 'address'"
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 '[email protected];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 :)
Hope this is the right issue tracker. Please advise if this is a doc problem (not software problem) in which case prolly I should have created an issue here instead: https://github.com/swagger-api/swagger.io/issues
Hi @chrisinmtown yes it's the right issue tracker.
We have to first determine if the problem is in swagger-ui or in swagger-client which actually executes requests for swagger-ui.
We started to use new library for form data lately, so this might be related with it.
I encountered similar issue where I reckon reason is performed JSON.stringify on the JSON object and as result the form field is supplied with string and not object. That causes validation failure and 400 as result from connexion. Check my reported issue https://github.com/swagger-api/swagger-ui/issues/7625
I had the same issue. But put extra information in the encoding section:
encoding:
profileImage:
contentType: image/png, image/jpeg
address:
contentType: application/json
Fix the issue