Skip to content

multipart formdata issue with spec #299

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

Closed
Wim-De-Clercq opened this issue Mar 22, 2021 · 3 comments · Fixed by #303
Closed

multipart formdata issue with spec #299

Wim-De-Clercq opened this issue Mar 22, 2021 · 3 comments · Fixed by #303

Comments

@Wim-De-Clercq
Copy link
Contributor

Wim-De-Clercq commented Mar 22, 2021

A schema which contains a path with the following can not be validated with openapi-core.
This relates to #231

      summary: multipart test
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object  # ---This is the issue. 
              properties:
                file:
                  type: string
                  format: binary
                name:
                  type: string

It can be resolved by not using type: object on the commented line. But https://swagger.io/docs/specification/describing-request-body/multipart-requests/ and https://swagger.io/docs/specification/describing-request-body/file-upload/ both give examples of schemas with it.

While it's not a huge deal to workaround, I feel like the library should be able to handle this.

Edit: It seems that without the object type, the validation just does not work. (I tried using an enum in the properties, and they are not validated).

I do see https://github.com/p1c2u/openapi-core/blob/b51d8104ac1fee1d99ff4a51caedf138e50ccb27/openapi_core/deserializing/media_types/factories.py#L8-L12

Does that mean there is only json support at the moment?


As a sidenote, the resulting "body" from validating formdata is quite raw (just a bytestring), I wonder if this could return something that's parsed a little bit more, but I do realise that multipart formdata is not the easiest thing.

@p1c2u
Copy link
Collaborator

p1c2u commented Mar 24, 2021

Hi @Wim-De-Clercq ,

Does that mean there is only json support at the moment?

that's correct, however you can add your custom deserializers . Check customization section for more information.

@wdembinski
Copy link

@p1c2u
Can you please provide an example how to register a custom deserializer? I'm working on version 0.16.6 and struggle to upload png image :(

@p1c2u
Copy link
Collaborator

p1c2u commented Mar 31, 2023

Hi @wdembinski

please report a separate bug and provide as much information as possible, thanks

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

Successfully merging a pull request may close this issue.

3 participants