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 form data cannot be validated has object #793

Closed
Fimeo opened this issue May 11, 2023 · 1 comment
Closed

Multipart form data cannot be validated has object #793

Fimeo opened this issue May 11, 2023 · 1 comment

Comments

@Fimeo
Copy link

Fimeo commented May 11, 2023

Hi!

I got an issue when I want to use the multipart form data content type to send a file.

I am using gin with getkin middleware to validate input requests.

The swagger defintion contains theses values:

post:
  operationId: saveUploadedFile
  tags:
  - Upload
  responses:
    '200':
      description: File successfully uploaded
  description: Upload a file to the storage bucket.
  requestBody:
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            upload:
              format: binary
              type: string
          required:
          - upload
    required: true

I have registered the multipart decoder :

openapi3filter.RegisterBodyDecoder("multipart/form-data", openapi3filter.FileBodyDecoder)

But with a curl like:

curl --location --request POST 'http://localhost:8080/uploads' \
--header 'accept: application/json' \
--header 'Content-Type: multipart/form-data' \
--form 'upload=@"/file.jpg"'

I still got the validation openapi3filter.RequestValidationInput with reason doesn't match schema, value must be an object.

But the input request has a object input and gin could find the form file using context.FormFile("upload").

Did I missed something about multipart definition?

Thanks :D

@Ol1BoT
Copy link

Ol1BoT commented Aug 2, 2023

Delete openapi3filter.RegisterBodyDecoder("multipart/form-data", openapi3filter.FileBodyDecoder)

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

2 participants