-
-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Hello!
On v2.1.2 (and dev-master) I've found that when the requestBody content uses the allOf keyword, I think it skips passed this check https://github.com/hotmeteor/spectator/blob/master/src/Validation/RequestValidator.php#L158 and goes into $actualBodySchema = $this->parseBodySchema();
However, if an empty request is passed through, parseBodySchema() will try to return an array [] and causes the following exception:
{"exception":"TypeError","message":"Spectator\\Validation\\RequestValidator::parseBodySchema(): Return value must be of type stdClass, array returned"}
This is a simplified example of what the OpenAPI schema looks like:
paths:
/test:
post:
summary: An endpoint
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TestRequest'
required: true
responses:
'201':
description: A response
content:
application/json:
schema:
type: object
properties:
data:
type: string
components:
schemas:
TestRequest:
allOf:
- $ref: '#/components/schemas/SharedSchema'
- type: object
properties:
added_property:
type: string
description: An additional object property
SharedSchema:
type: object
properties:
name:
type: string
This this is how we're trying to test that an empty request body causes a 422:
$this->postJson('/test', [], $token);
I’ve tried a quick fix by adding another condition to the if check, but I’m not sure if that’s the right approach.
|| $expectedBodyRawSchema->allOf
Thank you for your time 🙂