Skip to content

Add an equivalent to best_match() from jsonschema for oneOf and anyOf failures #72

@mtreinish

Description

@mtreinish

In the jsonschema library there is a best_match() function to try and match the underlying error from a failure in the schema validation: https://python-jsonschema.readthedocs.io/en/stable/errors/#best-match-and-relevance

This is especially useful in schemas with oneOfs in the schema because when there is an error in the payload being verified it results in the oneOf failing because none of the fields match. Which isn't normally useful when there is an error in an otherwise valid subschema causing the failure.

I've been working with using fastjsonschema on a particularly bad example of a schema for this case published here: https://qiskit.org/schemas/qobj_schema.json that uses large oneOfs often nested and figuring out the cause of a validation error with fastjsonschema is very difficult because it's often a top level oneOf rule that fails and the rule definition is the entire contents under that oneOf (which can be quite large). So the error messages returned by the JsonSchemaException doesn't really help for debugging, nor do any of the other exception parameters. I've had to either use best_match() from jsonschema on failure or if I have a known working example just looking at it side by side with the failure. Both of which are less than ideal.

It would be great enhancement to add some way of debugging these scenarios to the library so we can get the speed benefits of this library without having to sacrifice ease of debugging.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions