ajv
ajv copied to clipboard
Option: return errors as a tree
What version of Ajv you are you using?
What problem do you want to solve?
Improve readability of validation.errors
.
Currently error reporting is provided as a flat list in validate.errors
.
I find this list very hard to read and use to diagnose problems on large schema / instance.
What do you think is the correct solution to problem?
Provide a tree of errors instead of a flat list.
In single error mode, all the elements of the validation.errors
all trace back to a single failure which made ajv failed to validate.
Here is my understanding on how schema combinators should affect the tree:
-
not
: leaf because its child validates -
allOf
: absent because it forwarded its first child failure -
anyOf
: node whose children mirror the schema's children -
oneOf
: either a leaf if all its child validate or a node if some of them failed
Will you be able to implement it?
I did and it and it already helped us fix some issues: ajv-error-tree.
However I had the do the hacky job of reconstructing a tree from a flat list.
I believe that the clean solution would be to directly generate errors as a tree and flatten it if the user requires it.
Is this worth integrating in ajv
?
just want to say, this is exactly what we are looking for, our use case is to do an audit: At which point the rules are failing. This would help us track down the specific path to the value and why it fails
Hey @hyusetiawan, I developed ajv-error-tree to solve my issue. Feel free to use it directly or for inspiration.