You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that if a response specification has an item defined as object with no properties, the response is always considered valid even if it is in fact not valid.
For example, consider this definition in the spec (in a yaml file, with only relevant stuff):
data:
...required:
- id
- date
- custom_dataproperties:
id:
type: integerdescription: The unique IDexample: 1date:
type: integerdescription: The UNIX timestampexample: 1724750000custom_data:
type:
- object
- 'null'description: Custom data
you'd expect the validation to fail with an error like this
The properties must match schema: data
All array items must match schema
The required properties (id) are missing
object++ <== The properties must match schema: data
data: array <== All array items must match schema
object++ <== The required properties (id) are missing
id*: integer
date*: integer
...
But, even with an incorrect response (missing required id and date being a string), the response validation passes.
As soon as I add a property to custom_data, the validation fails as expected. The same thing applies to the array type without any items.
The thing is, I don't care what the structure of the custom_data object is, it could be any. In Stoplight, where I maintain the API spec, I can create an object without adding any properties.
So I had to work around this issue by specifying a dummy foo-bar object, listing all possible types, except object and array (because, apparently, it is what the issue is about):
Hello,
I noticed that if a response specification has an item defined as object with no properties, the response is always considered valid even if it is in fact not valid.
For example, consider this definition in the spec (in a yaml file, with only relevant stuff):
Having a response like this
using
you'd expect the validation to fail with an error like this
But, even with an incorrect response (missing required id and date being a string), the response validation passes.
As soon as I add a property to
custom_data
, the validation fails as expected. The same thing applies to thearray
type without anyitems
.The thing is, I don't care what the structure of the
custom_data
object is, it could be any. In Stoplight, where I maintain the API spec, I can create an object without adding any properties.So I had to work around this issue by specifying a dummy foo-bar object, listing all possible types, except object and array (because, apparently, it is what the issue is about):
And now the test fails as expected if an incorrect response is being returned.
I would expect validation to be performed correctly, and not skipped, if the spec contains an object with no properties or an array with no items.
PHP version is 7.4; Laravel 8; Spectator 1.8.0
Thank you.
The text was updated successfully, but these errors were encountered: