Open vileanco opened 2 years ago
Looking further into ajv docs https://ajv.js.org/guide/modifying-data.html#removing-additional-properties it looks like this is expected behavior. So I tried this also with the suggestion of adding discriminator property but still seeing same behavior.
I am running into the same issue here and after some debugging, I find that express-openapi-validator
does not pass distriminator: true
to ajv and the generated validate
function is incorrect. To generate the correct one, discriminator: true
has to be set. But there is no way to explicitly config ajv as express-openapi-validator
only extracts coerceTypes, removeAdditional
.
Same issue here
Same here
Seems like a lot of these problems are due to the OpenAPI spec itself simply does not support using additionalProperties: false
this way with combinators like anyOf
, allOf
.
From other discussion it seems this is fixed by the unevaluatedProperties: false
which is now supported by JSON Schema (and thus OAS 3.1), and AJV.
Seems like this PR will fix it
Describe the bug It looks like removeAdditional: "failing" response validation fails. I feel like the validator first tries to validate against type A and in progress removes property "extra", then it passes this to validate against B and it now also fails since "extra" field is missing. Note that the schema works if I change the order of TypeA and TypeB in the oneOf property.
To Reproduce I've added a test case that fails in my fork of this repo, link to commit:
https://github.com/vileanco/express-openapi-validator/commit/1963bd6d0f3dc101290df945d792bcc6fcc5c72f
Actual behavior Response validation fails with 500 "Internal server error". Errors returned
Expected behavior Response validation should pass.
Examples and context
Validator options:
Spec: