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

Validation Error when using OneOf in OpenAPI specs #110

Closed
ddobrin opened this issue Dec 19, 2018 · 3 comments
Closed

Validation Error when using OneOf in OpenAPI specs #110

ddobrin opened this issue Dec 19, 2018 · 3 comments
Assignees

Comments

@ddobrin
Copy link
Contributor

ddobrin commented Dec 19, 2018

The OneOf Validator iterates through the validators for each choice in OneOf and validates.
When it encounters the second "valid" schema element, it returns a validation error:

{ "error" : {"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - $.search: should be valid to one and only one of the schemas ","severity":"ERROR"} }

In this case, the matching element was the 8th out of 11th, however the code analyzed them one by one and failed in the second one already, where only the 8th is a true match.

The issue is in the PropertiesValidator, where it tries to find an entry by a key and does not find it.
It treats the "not found" as normal, instead of issuing an error and letting the OneOf Validator handle it gracefully (in this ignore it)
...
JsonNode propertyNode = node.get(entry.getKey());

        if (propertyNode != null) {
            errors.addAll(propertySchema.validate(propertyNode, rootNode, at + "." + entry.getKey()));

...

Proposed resolution includes the issuance of an error when property node does not match and letting the caller in the recursive chain handle it.

It must be properly validated and ascertained that there are no side-effects.

It is a showstopper for a number of APIs at a client site.

@ddobrin
Copy link
Contributor Author

ddobrin commented Dec 19, 2018

The fix can be reused and expanded upon in other validators, not only OneOf.

It revolves on how property validator handles missing nodes.
For some validators, the expectation is "ignore" which means success, for others "error".

NOTE: VALIDATORS must preserve the flag from the validators before, respectively following, therefore OneOf saves then re-sets the treat missing node as error, leaving other validators unaffected.

A document will add more details in the upcoming days in doc.networknt.com

@ddobrin
Copy link
Contributor Author

ddobrin commented Dec 19, 2018

ddobrin added a commit that referenced this issue Dec 21, 2018
@stevehu
Copy link
Contributor

stevehu commented Aug 13, 2019

From the OpenAPI 3.0 specification document, oneOf – validates the value against exactly one of the subschemas. If you have two or more subschemas valid, then an error should be thrown.

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

No branches or pull requests

2 participants