-
-
Notifications
You must be signed in to change notification settings - Fork 877
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
Support for discriminator tag lookup in referenced schemas #2261
Comments
Semantics of discriminator mean that oneOf should be used, not anyOf. Why is it needed? Discriminator in itself is no-op, but it is used as an optimisation for faster oneOf validation, requiring that the schema itself is consistent with "discriminator" semantics - that only one of the branches can be valid, and each branch requires a specific different value of discriminator tag. |
I see, the issue is not named correctly - it's about looking up the name in the referenced schemas. I don't think that it needs to be supported to be honest given the complexity. A simple workaround is to either construct the schema programmatically, so that it's included as the whole object, or to repeat the tag value on the top level. |
but happy to look at PR, if it's simple enough it might be ok... The traversal would simply stop then at the first schema that defines the tag value. |
The problem comes from the practices, that this is a valid schema definition for OAS. Repeating the "Base" object properties instead of using allOf would work, but results later in ugly code from the code generators based on this schema. This, because polymorphism then can not be used anymore and all objects get generated as own interface definitions. That's why such practices (combine oneOf with allOf) are preferred. |
Hi team, I'd like to see this (mapping) supported also. In trivial examples, working around mapping is straightforward. When handling an OAS it's a little more complicated as the referenced schemas can't just be renamed. At the very least, it would make it difficult to present useful errors back to users as the schema would have been transformed. Is the PR #2262 something you would consider and does it address the problem? |
Hi @epoberezkin, supporting OAS mapping would be really helpful because it becomes more and more common application in the projects that I participated in. I will vote for it as well. |
What version of Ajv you are you using?
8.12.0
What problem do you want to solve?
If the discrimantor property needs to be evaluated in a object which contains a allOf instead of direct properties, the discriminator can not be evaluated. Also the mapping param should be used if one exists.
Example of such a mapping:
What do you think is the correct solution to problem?
the getMapping function in the package discriminator needs to be extended tu support allOf for evaluation of the discriminator in the props of these subobjects.
Will you be able to implement it?
yes, PR will follow
The text was updated successfully, but these errors were encountered: