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

validate request with multipart makes body unretrievable #936

Open
aligator opened this issue Apr 9, 2024 · 0 comments
Open

validate request with multipart makes body unretrievable #936

aligator opened this issue Apr 9, 2024 · 0 comments

Comments

@aligator
Copy link

aligator commented Apr 9, 2024

with this route

  /api/import/7z:
    post:
      tags:
        - Import
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        "200":
          description: OK

The body is read by the ValidateRequestBody function.
After that function the body is read, and I can no longer read it. The value in openapi3filter/validate_request.go#L275 is actually never used because the defaultsSet is false.

I wouldn't expect the validator to read the full body in this case, as it is completely unnecessary.
Before I used the validator I had the route to "stream" the multipart body to avoid loading the whole file in RAM.

This makes no sense with a validator that reads the body anyway...

So two problems:

  • I didn't expect the validator to read the body in this route, as there is nothing to validate.
    Is there a way to provide a NoOp BodyDecoder which just does nothing and leaves the body reader as it is?
  • Reading the body by the validator without "reseting" the reader afterwards makes it impossible to retrieve the file.
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

1 participant