Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart request doc example for OpenAPI 3.0 fails with err "not of type 'object' - 'address'" #7560

Open
chrisinmtown opened this issue Oct 18, 2021 · 4 comments

Comments

@chrisinmtown
Copy link

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:

  1. Start the server
  2. Go to the endpoint with this content model
  3. Click on Try it out
  4. Browse to a file for upload; leave the suggested string-parameter values
  5. Click execute
  6. See the error in the response window area

Expected behavior

I was hoping the documentation example would work :)

@chrisinmtown
Copy link
Author

chrisinmtown commented Oct 18, 2021

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

@char0n
Copy link
Member

char0n commented Oct 20, 2021

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.

@wojtekm462
Copy link

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 #7625

@R-Rijnbeek
Copy link

R-Rijnbeek commented Feb 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants