Description
I had a realization today about what the text in section 10.3.2.1 says about the annotation result of properties
The annotation result of this keyword is the set of instance property names matched by this keyword.
How I interpreted this
I originally took this to mean that instance properties that were listed in properties
but were not matched merely weren't included in the annotation output. So in this schema and instance
{
"properties": {
"foo": true,
"bar": false
},
"additionalProperties": true
}
{ "foo": 1, "bar": 1 }
properties
would produce [ "foo" ]
because foo
would always pass, and bar
would never pass. The impact of this would be that bar
would then also be evaluated by additionalProperties
, which would pass.
This never really made sense to me because /properties/bar
would fail validation overall anyway, which means it doesn't matter that bar
passes additionalProperties
.
My realization
I now see that this requirement was stated this way to address the annotation result of the case that not all properties were present in the instance rather than the case where one of the properties failed validation.
This means that in the schema above and the instance { "foo": 1, "baz": 1 }
, properties
would produce [ "foo" ]
because bar
isn't present in the instance and baz
isn't listed in properties
.
So that means that properties
produces an annotation of the intersection of the properties it declares and the properties the instance contains, regardless of whether the property's value passes the associated subschema.
In the second case, it generally doesn't matter whether additionalProperties
is depends on the annotation because the schema's going to fail anyway.
Why does this matter?
It matters in error output. To illustration this, let's change additionalProperties
to false
:
{
"properties": {
"foo": true,
"bar": false
},
"additionalProperties": false
}
{ "foo": 1, "bar": 1 }
In my original interpretation, additionalProperties
evaluates bar
and produces an error.
In my new interpretation, it doesn't evaluate bar
and so no error is produced.
What am I asking?
Can we improve this text to more clearly specify which of these cases (or a third case, even) is intended? Personally, I like the "intersection" language I used above.
I think it was the "matched by this keyword" that threw me off. I took "matched" to mean "successfully validated."
(I think this has come up somwhere in a conversation between @karenetheridge and me.)