Description
The current interpretation is that if
does count annotations if it passes. We have tests that check for this and every current implementation behaves that way. However, @Relequestual brought up on slack that annotations should never count for if
because it's just a conditional whose purpose is to select between then
and else
.
Here's an example that illustrates the consequences of making such a change.
{
"type": "object",
"if": {
"properties": {
"foo": { "const": "then" }
},
"required": ["foo"]
},
"then": {
"properties": {
"bar": { "type": "string" }
},
"required": ["bar"]
},
"unevaluatedProperties": false
}
If we don't count if
annotations, then there is no value that matches the if
and passes validation over the whole schema. { "foo": "then", "bar": "" }
would pass the if
/then
, but fail the unevaluatedProperties
. The "foo" property declaration would have to be added outside of the if
. If we can determine any reason why that would be a bad thing, then we shouldn't change anything. I can't think of any good reason for it.
Another way to think about it is, what is the behavior of unevaluatedProperties
using the Implication Pattern. if
/then
is supposed to be sugar for the Implication Pattern, so I would expect them to work the same with unevaluatedProperties
. Here's the same example as above except with implication,
{
"type": "object",
"anyOf": [
{
"not": {
"properties": {
"foo": { "const": "then" }
},
"required": ["foo"]
}
},
{
"properties": {
"bar": { "type": "string" }
},
"required": ["bar"]
}
],
"unevaluatedProperties": false
}
Now the annotations from the "if" don't apply because of the not
schema. So, that indicates that it might be desirable for if
to not count annotations to be compatible with implication. To me, that's a pretty convincing argument that we go this wrong and annotations from if
schemas should never be counted.