Closed wcloete closed 1 year ago
@wcloete Thank you for your report, but I use Ajv under the hood for the validation and it only supports oneOf
with the discriminator keyword (yet), so there's not much I can do about it at this point.
@wcloete I just had a closer look at your example again.. Your example is not how the discriminator is supposed to be used (see also the Discriminator-section).
If you just want to make a model composition, you don't need the discriminator
. Drop the discriminator
it in your example and it works.
Strange, because as I say, I took the schemas almost verbatim from the docs - my only change was to remove mapping
and add an endpoint.
The paragraph above the example even says
In both the oneOf and anyOf use cases, all possible schemas MUST be listed explicitly. To avoid redundancy, the discriminator MAY be added to a parent schema definition, and all schemas comprising the parent schema in an allOf construct may be used as an alternate schema.
But as you say, Ajv only supports oneOf
according to their documentation, so this one will keep failing until they add support.
Thank you for your time, and for a nice library!
I was about to post an example with a oneOf
, a discriminator and a allOf
example, but then figured that it doesn't work due to this bug: https://github.com/ajv-validator/ajv/issues/2261 , but then saw that you already saw https://github.com/ajv-validator/ajv/issues/2281 😉 .. I have a watch on 2261
and when the corresponding pull request is merged, I'll look into it again.
I can't promise that this will resolve your issue, but 2261
really is a problem as that is a common use case.
Yes, it looks like 2261 covers what I need. I'll keep an eye out for updates too.
Hi since https://github.com/codekie/openapi-examples-validator/pull/185 I have an API that is failing validation. It uses the
discriminator
keyword on the parent definition andallOf
on the children.Example
This was adapted from the OAS documentation for
discriminator
API spec:
Validate with:
Error:
Other info
Version: openapi-examples-validator@5.0.0 Operating system: https://hub.docker.com/_/node, image ID acd15857ce39 OpenAPI version: 3.0.3