jsonschema
jsonschema copied to clipboard
Pick the deepest error among the most relevant ones in each separate subschema
Improves best_match
in the presence of anyOf
/ oneOf
. Calculate the most relevant error in each separate subschema and choose the deepest one.
In particular, for anyOf
/ oneOf
keywords with the only subschema, the best error is resolved as if the subschema was not enclosed by these keywords.
To reproduce:
from jsonschema import Draft202012Validator as Validator, exceptions
for applicator in "anyOf", "oneOf":
# Should match {"properties": {"foo": {"minProperties": 2}}
schema = {
applicator: [
{
"properties": {
"foo": {
"minProperties": 2,
"properties": {"bar": {"type": "object"}},
},
},
},
],
}
instance = {"foo": {"bar": []}}
error = exceptions.best_match(Validator(schema).iter_errors(instance))
print(error)
Revert main code changes in commit https://github.com/python-jsonschema/jsonschema/commit/b20234e86c4dadf5d691400383a6fc0a1e9afc34 preserving the tests.
Closes: #1257
📚 Documentation preview 📚: https://python-jsonschema--1300.org.readthedocs.build/en/1300/