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

Improve the handling of complex, summary-type jsonschema errors #969

Open
4 tasks
martonvago opened this issue Jan 14, 2025 · 0 comments
Open
4 tasks

Improve the handling of complex, summary-type jsonschema errors #969

martonvago opened this issue Jan 14, 2025 · 0 comments

Comments

@martonvago
Copy link
Contributor

Currently, when we transform jsonschema's ValidationErrors into CheckErrors, we don't preserve relationships between errors. For example, in the case where any of two fields must be present on an object, if both fields are missing, we output a CheckError for both. From this output alone, it is not possible to tell that filling in either of those fields would have resolved the issue.

One idea is to add a group attribute to CheckError that would make it possible to retain these relationships between errors. So in a case like the above, the output would be:

[
    {
        "message": "'data' is a required property",
        "json_path": "$.data",
        "validator": "required",
        "group": "oneOf-1",
    },
    {
        "message": "'path' is a required property",
        "json_path": "$.path",
        "validator": "required",
        "group": "oneOf-1",
    },
]

Using this output, it is possible to tell which errors belong to one group, and the name of the group implies that only one of the errors needs to be fixed.

Tasks:

  • Add a group attribute to CheckError. Should be optional.
  • Modify validation_errors_to_check_errors to populate the group field of CheckErrors. For this, an initial strategy might be looking at each ValidationError in the flattened list and checking if it is a child of a complex / summary-type error (validators for this listed in COMPLEX_VALIDATORS). ValidationErrors should have this information on them. When naming the group, keep the name unique within the list of errors (there may be multiple oneOf-type groups!) -- e.g., add a number.
  • Update tests.
  • Consider whether the information captured by group should be translated into a more user-friendly error message when the errors are displayed. For this, look at FailedCheckError and how it displays its list of CheckErrors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant