jsonschema icon indicating copy to clipboard operation
jsonschema copied to clipboard

Validation errors should be able to indicate that a single error should be produced without collecting all of the details ahead of time

Open Julian opened this issue 6 years ago • 0 comments

In general, validation is lazy -- if only one error is needed (in the sense that it is known that an instance is invalid), only one is produced.

There are however (somewhat unintentional) exceptions.

E.g.:

  • anyOf and oneOf calculate the .context of the first error they yield by calculating all sub-errors that were generated. This is because ValidationError.context needs to be provided on __init__.
  • dependentRequired, on the other hand, yields many errors, one for each missing required property (see also #119)

What's happening in these situations is that the validation function knows an error has occurred -- it wants to yield an error, but in order to do so, it needs to calculate the full details required so that the error is "complete".

We should instead have a way to indicate a validation error has occurred, but delay fully calculating its contents until/unless they are requested.

Julian avatar Jan 14 '19 14:01 Julian