Skip to content

WIP: [node-core-library] In JsonSchema, replace z-schema with Ajv for schema validation#2047

Open
renoirb wants to merge 1 commit intomicrosoft:mainfrom
renoirb:renoirb/jsonschema-ajv
Open

WIP: [node-core-library] In JsonSchema, replace z-schema with Ajv for schema validation#2047
renoirb wants to merge 1 commit intomicrosoft:mainfrom
renoirb:renoirb/jsonschema-ajv

Conversation

@renoirb
Copy link
Contributor

@renoirb renoirb commented Jul 22, 2020

@ghost
Copy link

ghost commented Jul 22, 2020

CLA assistant check
All CLA requirements met.

@renoirb renoirb changed the title WIP: Replace z-schema for Ajv WIP: [node-core-library] In JsonSchema, replace z-schema as JSONSchema validator for Ajv Jul 22, 2020
}
// if (errorDetail.inner) {
// buffer = JsonSchema._formatErrorDetailsHelper(errorDetail.inner, indent + ' ', buffer);
// }
Copy link
Contributor Author

@renoirb renoirb Jul 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 be small or medium
  • I also tried matching size=large, but in that case your kind needs to be circle

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@renoirb renoirb changed the title WIP: [node-core-library] In JsonSchema, replace z-schema as JSONSchema validator for Ajv WIP: [node-core-library] In JsonSchema, replace z-schema with Ajv for schema validation Jul 23, 2020
@renoirb
Copy link
Contributor Author

renoirb commented Jul 30, 2020

@octogonz octogonz requested a review from dmichon-msft as a code owner April 22, 2023 19:03
@iclanton
Copy link
Member

This would probably still be useful if someone wants to pick this back up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

3 participants