-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Unexpected errors for anyOf schemas with additionalProperties: false #127
Comments
Thanks @thetumper. Could you send me a snippet of the Ajv code that you used to compare validation; I'm particularly interested in those options. |
Crud! I'm sorry. I realized the test case with Ajv was missing the scenario of having two contact mechanism types in the payload. It fails for Ajv also. Tests with Ajv here: https://github.com/thetumper/contact-schema-validator Looks like this is related to the known issue of combining schemas and restricting additional properties described here: https://json-schema.org/understanding-json-schema/reference/combining.html I'll probably have to go with a workaround such as this: https://stackoverflow.com/questions/22689900/json-schema-allof-with-additionalproperties Seems it will mess a bit with where the properties are displayed in a Swagger UI viewer, but if I can get the needed behavior, I'll live with that. Sorry for the false alarm! :( |
Drat. That doesn't work. When I move the property restriction out, an invalid property is not caught. The invalid data is seen as "extra" properties on the other sub-schema, which doesn't have restrictions/criteria for them. I'll commit an updated schema and test showing that. Although...this seems to be more of an Ajv or general problem, not particular to express-openapi-validator. |
@thetumper Thanks for investigating this issue. If you believe it is an Ajv issue, please feel free to file an issue there. Perhaps link it here, so I can track progress and integrate the fix when available |
Filed an issue on ajv: It may result in "this is a known limitation of the spec", but we'll see. Thanks! |
@cdimascio I was able to resolve this issue with changes to the schema definitions, after finding an example on another ajv issue. My latest commit has the changes that resolved it for me, in case anyone is interested: https://github.com/thetumper/contact-schema-validator I'm closing this issue, as there is a resolution at least for the scenario I was trying to specify, and it is related to the JSON schema spec anyway, not this or any other particular library that validates against openapi or JSON schema. Thanks for a great package/utility! |
The following is a portion of my openapi 3.0 spec, just the relevant schemas:
The contactMechanisms element should be allowed to have more than one of the "sub-schemas" represented, but the additionalProperties: false on each sub-schema seems to be "seen" across the contactMechanisms element, instead of being isolated to the sub-schema it is defined on.
This payload should be valid, with no errors:
Instead, express-openapi-validator returns these errors:
Ajv correctly validates this, returning no errors.
The text was updated successfully, but these errors were encountered: