spectator icon indicating copy to clipboard operation
spectator copied to clipboard

Convert empty request body to object if an object is expected by OpenAPI definition

Open gdebrauwer opened this issue 1 year ago • 0 comments

If I execute an API call without a request body

$this->patchJson('/pets')->assertValidRequest();

and my OpenAPI file says the request can contain an object (none of the properties are required),

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties: # none of the properties are required
                name:
                  type: string

then I currently get the following error:

The data (array) must match the type: object

object++ <== The data (array) must match the type: object
    name: string

This PR fixes that. If the OpenAPI file says that an object is expected, then the empty array is converted to an empty object.

gdebrauwer avatar Apr 02 '24 15:04 gdebrauwer