-
Notifications
You must be signed in to change notification settings - Fork 308
#1112 - Support JSON Schema 2019-09 and 2020-12 by migrating to @hyperjump/json-schema #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
#1112 - Support JSON Schema 2019-09 and 2020-12 by migrating to @hyperjump/json-schema #1115
Conversation
Replace AJV dependencies with @hyperjump/json-schema to reduce bundle size and prepare for JSON Schema 2019-09/2020-12 support. Simplifies schema meta-validation while maintaining backward compatibility.
f6b2134 to
c2874e5
Compare
c2874e5 to
bfa433e
Compare
|
@datho7561 FYI #1006 |
1d275c1 to
115dc4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
|
We need this ! |
|
Amazing, really need this ! When can this be merged? |
|
I would love this as well! 👍 |
|
@msivasubramaniaan Hello dear Sir, |
|
@gorkem please please :-) |
|
Nice job ! |
|
I'm planning finishing the release of 1.19.0 first (since we started the release process and never finished), but I intend to take a look at this after 1.19.0 is published. |
|
Thank you @datho7561 ! |
|
Few notes for now, but I'll keep testing this PR tomorrow:
|
|
For this PR, keep in mind (I forgot this myself) that AJV (and now i.e. If you have this YAML file called # yaml-language-server: $schema=./product.schema.json
productId:
productId: 12AJV/ |
datho7561
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code is working okay. I think the test cases need reworking.
I also think we have to be careful about the wording; this PR will not support validating YAML against 2019-09 and 2020-12 schemas, but it will be able to point out errors in those schemas.
| expect(schema.schema.type).eqls('array'); | ||
| }); | ||
|
|
||
| it('should handle schemas that use draft-04', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests make sure that you can validate YAML against 2019-09 and 2020-12 schemas. However, this functionality is handled by vscode-json-languageservice ./src/languageservice/parser/jsonParser07.ts, not AJV or hyperjump/json-schema. As a result, I don't think that these tests are helpful.
The main thing that's changed by this PR is how the schema referenced in the yaml file is validated. (If the schema is invalid, we add an error on the YAML file).
In order to test this properly, I think it would be helpful to write tests that validate against some invalid schemas, to make sure that the errors are found.
Here's an interesting case I came up with:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$defs": {
"person": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"birthday": {
"type": "string",
"format": "datetime"
},
"location": {
"type": ["nostril", "nostril"]
}
},
"required": [
"name",
"birthday",
"location"
],
"additionalProperties": false
}
},
"type": "array",
"items": {
"$ref": "#/$defs/person"
}
}When validated as a draft-07 schema, this schema is listed as valid, since $defs has no meaning in draft-07. However, when validated as a 2019-09 schema, ["nostril", "nostril"] is marked as a bad type.
We need something similar for for 2020-12; something that's invalid in 2020-12 schemas but okay in 2019-09 schemas.
| # YAML Language Server | ||
|
|
||
| Supports JSON Schema 7 and below. | ||
| Supports JSON Schema draft-04, draft-07, 2019-09, and 2020-12. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR will validate referenced schemas properly, but doesn't validate the YAML against the referenced schemas properly if they are newer than draft-07, as this behaviour is handled by vscode-json-languageservice ./src/languageservice/parser/jsonParser07.ts.
Support JSON Schema 2019-09 and 2020-12 by migrating to @hyperjump/json-schema
🎯 Overview
Fixes #1112 by replacing AJV with
@hyperjump/json-schemato enable support for JSON Schema 2019-09 and 2020-12 specifications.🔄 Key Changes
Dependency Migration
ajvandajv-draft-04(limited to draft-04/07)@hyperjump/json-schema(supports all drafts including Draft 04, Draft 07, 2019-09, 2020-12)Schema Service Updates
yamlSchemaService.ts$defskeywordunevaluatedPropertiesexclusiveMinimum/exclusiveMaximumComprehensive Test Coverage