hotmeteor / spectator

OpenAPI testing for PHP
MIT License
285 stars 53 forks source link

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

Open gdebrauwer opened 7 months ago

gdebrauwer commented 7 months ago

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.