Skip to content
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

Not compatible with oneOf/anyOf/allOf, not #58

Closed
bilfeldt opened this issue Jul 5, 2021 · 5 comments
Closed

Not compatible with oneOf/anyOf/allOf, not #58

bilfeldt opened this issue Jul 5, 2021 · 5 comments

Comments

@bilfeldt
Copy link
Contributor

bilfeldt commented Jul 5, 2021

It is possible to use the oneOf, anyOf or allOf notation in OpenAPI 3.0 Schemas as described in the official documentation here when describing requests/responses, but this causes a problem when trying to compare the schema.

The original error was

The data (string) must match the type: object 

Now this is caused by src/Validation/RequestValidator.php#L116:

if ($jsonSchema->type === 'object' || $jsonSchema->type === 'array') { ...

where we also need to check for these type of schemas:

if ($jsonSchema->type === 'object' || $jsonSchema->type === 'array' || $jsonSchema->oneOf || $jsonSchema->allOf || $jsonSchema->anyOf) { ...

Making this change causes the body to be converted correctly, but the next issue arising is that the type property seems to be required as it failed with the validation exception of:

The required properties (type) are missing

It seems that the codebase is not capable of handling the oneOf/anyOf/allOf cases but I have not been able to figure out if this is a quick fix or if the codebase is tightly coupled to the requirement of a type.

@hotmeteor
Copy link
Owner

Ya this is a known limitation, we've hit it as well in our own API testing. It's actually a shortcoming in the underlying parsing library.

When I find time to dig on it a bit more I will and update here.

@hotmeteor
Copy link
Owner

@bilfeldt OK, I have a branch I'm working on that provides support for anyOf and oneOf (allOf is still not working).

However, iIt appears that in order to use oneOf you need to either defined required properties or set additionalProperties: false. The oneOf documentation doesn't have this, but this is in error. You can find more details in this thread here: stoplightio/spectral#1482 (comment)

@bilfeldt
Copy link
Contributor Author

@bilfeldt OK, I have a branch I'm working on that provides support for anyOf and oneOf (allOf is still not working).

However, iIt appears that in order to use oneOf you need to either defined required properties or set additionalProperties: false. The oneOf documentation doesn't have this, but this is in error. You can find more details in this thread here: stoplightio/spectral#1482 (comment)

Dear @hotmeteor thanks for taking the time to look at this. Do you have a branch which I should have a look at? The least I can do is test if this solves the issues I have been facing with this.

@hotmeteor
Copy link
Owner

@bilfeldt Try this one: #59

@hotmeteor
Copy link
Owner

This should be resolved in https://github.com/hotmeteor/spectator/releases/tag/v1.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants