fix: recursively check for validity of discriminator#2597
Open
AmadeusK525 wants to merge 1 commit intoajv-validator:masterfrom
Open
fix: recursively check for validity of discriminator#2597AmadeusK525 wants to merge 1 commit intoajv-validator:masterfrom
AmadeusK525 wants to merge 1 commit intoajv-validator:masterfrom
Conversation
4aba655 to
f3ed917
Compare
The old implementation was only checking for a single level of validity
of a schema using the discriminator extension, without accounting for
"unions of unions". So, for example:
```json
{
"discriminator": {
"propertyName": "field"
}
"required": ["field"],
"oneOf": [
{
"oneOf": [
{
"properties": {
"field": { "const": "a" }
},
"required": ["field"]
},
{
"properties": {
"field": { "const": "b" }
},
"required": ["field"]
}
],
"required": ["field"]
},
{
"properties": {
"field": { "const": "c" }
},
"required": ["field"]
}
]
}
```
This schema would fail because the compiler would complain about the
first schema in `oneOf` not having the `field` property, which was
defined as the `discriminator`. But it *does* have that property, just
in a subschema inside another `oneOf` definition!
f3ed917 to
7ccf749
Compare
Member
|
It's debatable it's correct, given how discriminator is specified I think. |
Author
@epoberezkin Sorry, but why would this be debatable? The spec may not mention recursion explicitly, but there's no reason to not cover this case, as it's in line with the reasoning behind the discriminator keyword (making sure that every object in the discriminated union has the discriminator property). I really don't see how an implementation that doesn't cover the recursion "edge" case would be more correct than one that doesn't |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The old implementation was only checking for a single level of validity of a schema using the discriminator extension, without accounting for "unions of unions". So, for example:
{ "discriminator": { "propertyName": "field" } "required": ["field"], "oneOf": [ { "oneOf": [ { "properties": { "field": { "const": "a" } }, "required": ["field"] }, { "properties": { "field": { "const": "b" } }, "required": ["field"] } ], "required": ["field"] }, { "properties": { "field": { "const": "c" } }, "required": ["field"] } ] }This schema would fail because the compiler would complain about the first schema in
oneOfnot having thefieldproperty, which was defined as thediscriminator. But it does have that property, just in a subschema inside anotheroneOfdefinition!