-
Notifications
You must be signed in to change notification settings - Fork 96
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
JSON object not accepted as part of multipart payload #234
Comments
I spent some time digging around in the source code for the validator. I did find this interesting discrepancy: openapi-psr7-validator/src/PSR7/Validators/BodyValidator/MultipartValidator.php Lines 99 to 104 in a665e22
VS openapi-psr7-validator/src/PSR7/Validators/BodyValidator/MultipartValidator.php Lines 297 to 301 in a665e22
The former contains this line to parse the body before validating, where the latter does not: $body = $this->deserializeBody($this->parseMultipartData($addr, $document), $schema); I tried copying that line from the |
It looks like after this block: openapi-psr7-validator/src/PSR7/Validators/BodyValidator/MultipartValidator.php Lines 290 to 294 in a665e22
Something needs to happen to parse the JSON here before validation. If I can figure this out, I'll submit a PR, but I may have to defer to someone who knows the codebase if I can't. Advice would also be appreciated. |
I've found if I change this: openapi-psr7-validator/src/PSR7/Validators/BodyValidator/MultipartValidator.php Lines 297 to 301 in a665e22
To this: try {
$body = $this->deserializeBody($body, $schema);
$validator->validate($body, $schema);
} catch (SchemaMismatch $e) {
throw InvalidBody::becauseBodyDoesNotMatchSchema($this->contentType, $addr, $e);
} And also change this:
To this: $param = new SerializedParameter($propSchema, 'application/json'); Then the request is validatated properly (well, at least, assuming I only have JSON data in the request obviously...). The only remaining question is how to actually get the expected content type rather than hard-coding it. The existing |
The validator does not appear to accept JSON objects as "properties" of a multipart payload. For example, in this trimmed-down schema:
When sending an
application/json
request, the validator accepts the request:However, if I wrap the exact same data in a
multipart/form-data
payload, it fails by throwing a\League\OpenAPIValidation\Schema\Exception\TypeMismatch
exception on thedata
property with the message "Value expected to be 'object', but 'string' given."According to this link, I should be able to have a JSON part in a multipart payload by specifying
type: object
. The 3.1 spec also states that JSON should be the default encoding for "object" properties in a multipart payload. The validator, however, seems to only interpret the content as a string.The text was updated successfully, but these errors were encountered: