-
Notifications
You must be signed in to change notification settings - Fork 35
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
oneOf where more than 2 types inside an array #257
Comments
Thanks for raising this @harveyappleton 🙂 I may have time next weekend to look at this. In the meantime if you'd like to recreate this using this file: https://github.com/openapi-library/OpenAPIValidators/blob/master/packages/jest-openapi/__test__/bugRecreationTemplate.test.ts (just clone the repo and post a link to your branch here). That will help speed up my investigation |
Hey @rwalle61 - think I might have found cause of issue AND produced a demo https://github.com/harveyappleton/OpenAPIValidators/tree/master Clone this fork You should see the failing test ● Recreate bug (issue #257) › passes
expect(received).toSatisfyApiSpec() // Matches 'received' to a response defined in your API spec, then validates 'received' against it
expected received to satisfy the '200' response defined for endpoint 'GET /recreate/bug' in your API spec
received did not satisfy it because: included/1/type must be equal to one of the allowed values, included/1/attributes must have required property 'rating', included/1/attributes must NOT have additional properties, included/1/type must be equal to one of the allowed values, included/1/type must be equal to one of the allowed values, included/1/attributes must have required property 'description', included/1/attributes must NOT have additional properties, included/1 must match exactly one schema in oneOf, included/3/type must be equal to one of the allowed values, included/3/attributes must have required property 'rating', included/3/attributes must NOT have additional properties, included/3/type must be equal to one of the allowed values, included/3/type must be equal to one of the allowed values, included/3/attributes must have required property 'description', included/3/attributes must NOT have additional properties, included/3 must match exactly one schema in oneOf
received contained: {
body: {
included: [
{ type: 'Apple', attributes: { rating: 5 } },
{ type: 'AppleOrange', attributes: { isTasty: true } },
{
type: 'Banana',
attributes: { description: 'Yellow and sumptuous' }
},
{ type: 'AppleOrange', attributes: { isTasty: false } },
{
type: 'Banana',
attributes: { description: 'Another thing about a banana' }
}
]
}
} It is because it seems to match If you change Schema & test file are in: Hope that helps |
Thanks @harveyappleton ! I didn't have time to investigate this weekend but you've given me a great starting point for when I can. Seems like something odd is happening |
No problems @rwalle61 - if you can point me in the right direction, I might be able to do a fix for this :) |
@rwalle61 any progress on the oneOf issues? |
I have similar problem with the following:
|
Sorry I don't have time to investigate this further, happy for someone else to take a closer look 🙂 we parse the OpenAPI spec and pass the schemas to a 3rd party validator (openapi-response-validator) so it would be good to confirm if the bug is in our code or theirs (in my experience, it is probably ours 😁) |
Are you using jest or chai?
Jest
Are you using OpenAPI 2, 3.0.X, or 3.1.0?
OpenAPI 3.0.3
Describe the bug clearly
When I use
oneOf
for items in an array with more than 2 distinct references, it fails randomly and can't discriminate which is the matched entity type (even withdiscriminator
property).Steps to reproduce the bug:
oneOf
with more than 2 - for example(my actual entities are more complex than this, but for the sake of a simple bug description, this will suffice)
What did you expect to happen instead?
It validates the array correctly
Are you going to resolve the issue?
If I'm pointed in the right direction I may be able to!
The text was updated successfully, but these errors were encountered: