Skip to content

Poor errors when anyOf is used #1002

Open
@ssbarnea

Description

@ssbarnea

While refactoring as schema I had to make use of anyOf to distinguish between a v1 of the format and v2 of it (based on presence of a version const property). This worked well with the json validator used by vscode but I observed that on python-jsonschema the error became too generic to be useful to the user.

As my schema is bit more complex, I will try to provide a minimal reproducer for the issue, hoping that we can tune it to improve the messaging.

I did create a repository with a minimal scheme that reproduce the current behavior at https://github.com/ssbarnea/rep-a

Instead of reporting the fact that "description" is not of type string, the library reports the generic message:

{'version': 1, 'description': 0}: {'version': 1, 'description': 0} is not valid under any of the given schemas

Is there any way we can write such a schema to avoid getting such a generic error?

Please note that in reality the schemas are considerably more complex, with lots of properties for each version, but if the user only gets one such top-lever error, they will never be able to spot the root cause of the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementSome new desired functionalityError ReportingIssues related to clearer or more robust validation error reporting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions