Skip to content

[Bug]: RequestBodyValidationError when sending image for multipart form data #761

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
seththoburn-cc opened this issue Jan 15, 2024 · 1 comment
Labels
kind/bug Indicates an issue

Comments

@seththoburn-cc
Copy link

Actual Behavior

This seems to be the same as #630, but I'm getting a RequestBodyValidationError. It's thrown by a MediaTypeDeserializeError further up. Here are the relevant parts of the stacktrace:

  File "openapi_core/deserializing/media_types/util.py", line 24, in <dictcomp>
    part.get_param("name", header="content-disposition"): part.get_payload(
AttributeError: 'str' object has no attribute 'get_param'

  File "openapi_core/deserializing/media_types/deserializers.py", line 31, in deserialize
    raise MediaTypeDeserializeError(self.mimetype, value)
openapi_core.deserializing.media_types.exceptions.MediaTypeDeserializeError: Failed to deserialize value with multipart/form-data mimetype: --------------------------5ccec95762968d0b
Content-Disposition: form-data; name="file"; filename="Rectangle 40044.png"
Content-Type: image/png


  File "openapi_core/validation/decorators.py", line 58, in _raise_error
    raise init(**kw) from exc
openapi_core.validation.request.exceptions.RequestBodyValidationError: Request body validation error

Expected Behavior

The body is validated

Steps to Reproduce

Following schema:

"/uploads": {
      "post": {
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "properties": {
                  "file": { "format": "binary", "type": "string" }
                },
                "required": ["file"],
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": { "id": { "format": "uuid", "type": "string" } }
                }
              }
            },
            "description": "Upload created successfully"
          },
        },
        "security": [{ "bearerAuth": [] }],
        "summary": "Create an upload",
        "tags": ["upload"]
      }
    }

Request:

curl -X POST \
 -H  "Content-type: multipart/form-data" \
 -H "Authorization: Bearer TOKEN" \
 -F "file=@/Users/seththoburn/Downloads/Rectangle 40044.png" \
 https://localhost:3000/api/v1/uploads

OpenAPI Core Version

0.18.2

OpenAPI Core Integration

flask

Affected Area(s)

unmarshalling

References

#630

Anything else we need to know?

No response

Would you like to implement a fix?

None

@seththoburn-cc seththoburn-cc added the kind/bug Indicates an issue label Jan 15, 2024
@seththoburn-cc
Copy link
Author

Turns out this is fixed in 0.19.0a1, I had thought it was supposed to be fixed in 0.18.2.

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

No branches or pull requests

1 participant