Skip to content
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

Pick the deepest error among the most relevant ones in each separate subschema #1300

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ilia1243
Copy link

@ilia1243 ilia1243 commented Sep 15, 2024

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 b20234e preserving the tests.

Closes: #1257


📚 Documentation preview 📚: https://python-jsonschema--1300.org.readthedocs.build/en/1300/

ilia1243 and others added 2 commits September 15, 2024 13:16
…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.

Revert main code changes in commit b20234e preserving the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mitigate undesired side effect of new best_match behaviour with alternative proposal
1 participant