WIP: [node-core-library] In JsonSchema, replace z-schema with Ajv for schema validation#2047
WIP: [node-core-library] In JsonSchema, replace z-schema with Ajv for schema validation#2047renoirb wants to merge 1 commit intomicrosoft:mainfrom
Conversation
| } | ||
| // if (errorDetail.inner) { | ||
| // buffer = JsonSchema._formatErrorDetailsHelper(errorDetail.inner, indent + ' ', buffer); | ||
| // } |
There was a problem hiding this comment.
Not sure where in Ajv inner would be nested, Ajv ValidationError does not have a nested tree. But Z-Schema only adds to errorDetails.inner through Report.addCustomError and isn't that much used.
Current hypothesis: inner may be about a nested Schema, if that's so, maybe there's another name for the same idea in Ajv.
There was a problem hiding this comment.
Consider a schema that allows possibilities like this:
option 1:
- kind=square
- size=small
option 2:
- kind=square
- size=medium
option 3:
- kind=circle
- size=medium
option 4:
- kind=circle
- size=large
And then suppose your input is { kind=square, size=large }. Then the error message has to say something like:
- I tried matching
kind=square, but in that case the size needs to besmallormedium - I also tried matching
size=large, but in that case your kind needs to becircle
The reason is that the any of and all of constructs don't always have a way to tell the engine that kind is a special important property and size is a secondary detail. The schema just sees possible patterns, so the error message often won't be understandable without more explanation of how it tried to match it. And this problem can get nested arbitrarily in complex schemas, so it ends up being a tree.
I know that the newer JSON Schema supports mechanisms like inheritance that make this problem better. And ajv itself might have better ways of reporting error messages. If so -- we should try to tailor JsonSchema around that rather than forcing it to use z-schema's design. The goal is informative error messages.
There was a problem hiding this comment.
(If I can find some more time, I'll see if I can dig up an actual test case that better illustrates a case where nesting error messages were helpful.)
There was a problem hiding this comment.
Yes, at least one schema, and a few fixtures where we know what errors should throw.
Not the shape of the error, known and easy to spot fixture where we could see quickly where.
|
Some bookmarks for next session;
|
|
This would probably still be useful if someone wants to pick this back up. |
As per conversation with Pete Gonzalez, about replacing z-schema to Ajv