yaml-language-server icon indicating copy to clipboard operation
yaml-language-server copied to clipboard

#1112 - Support JSON Schema 2019-09 and 2020-12 by migrating to @hyperjump/json-schema

Open damioune123 opened this issue 7 months ago • 18 comments

Support JSON Schema 2019-09 and 2020-12 by migrating to @hyperjump/json-schema

🎯 Overview

Fixes #1112 by replacing AJV with @hyperjump/json-schema to enable support for JSON Schema 2019-09 and 2020-12 specifications.

🔄 Key Changes

Dependency Migration

  • Removed: ajv and ajv-draft-04 (limited to draft-04/07)
  • Added: @hyperjump/json-schema (supports all drafts including Draft 04, Draft 07, 2019-09, 2020-12)

Schema Service Updates

  • Simplified validation logic in yamlSchemaService.ts
  • Maintained full backward compatibility with existing draft-04/07 schemas
  • Added native support for modern JSON Schema features:
    • $defs keyword
    • unevaluatedProperties
    • Modern exclusiveMinimum/exclusiveMaximum

Comprehensive Test Coverage

  • 11 new test cases validating 2019-09 and 2020-12 support
  • Test fixtures for both schema versions
  • Verification of modern keyword handling
  • Mixed version compatibility testing

damioune123 avatar Jul 22 '25 19:07 damioune123

@datho7561 FYI #1006

damioune123 avatar Jul 22 '25 22:07 damioune123

Coverage Status

coverage: 83.964% (+0.008%) from 83.956% when pulling c3abaf3c6765fb290f2e6bfc27d8aa3ab543c3a1 on damioune123:feature/1112-support-json-schema-2019-and-2020 into 3821411ee8c92e5b7e5ca88f84ab443ae3b2791a on redhat-developer:main.

coveralls avatar Jul 25 '25 14:07 coveralls

We need this !

ernestmajdalani avatar Aug 19 '25 20:08 ernestmajdalani

Amazing, really need this ! When can this be merged?

HanyAkoury avatar Aug 19 '25 20:08 HanyAkoury

I would love this as well! 👍

Kosta-Github avatar Sep 02 '25 16:09 Kosta-Github

@msivasubramaniaan Hello dear Sir, Would it be possible to have a review on this Pull request as it is of high importance and for now, asserted public utility ? Thank you for your feedback and have a blessed day. Regards

HanyAkoury avatar Sep 17 '25 08:09 HanyAkoury

@gorkem please please :-)

injeniero avatar Sep 23 '25 14:09 injeniero

Nice job !

hadriencoursera avatar Sep 23 '25 14:09 hadriencoursera

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.

datho7561 avatar Sep 23 '25 15:09 datho7561

Thank you @datho7561 !

HanyAkoury avatar Sep 25 '25 08:09 HanyAkoury

Few notes for now, but I'll keep testing this PR tomorrow:

  • I can't get either of $dynamicRef (from 2019-09) or $recursiveRef (from 2020-12) working properly. I thought proper support for these features was the main selling point of swapping from AJV to hyperjump's JSON Schema validator. Can you confirm if this is expected to work?
  • Since this PR was opened, it seems like AJV has added support for 2020-12 (at least from what I can tell from the docs). It would be less risky to stick with AJV for validation instead of changing libraries, especially if it can support everything that hyperjump can. What are the advantages of hyperjump's implementation over AJV?

datho7561 avatar Sep 25 '25 21:09 datho7561

For this PR, keep in mind (I forgot this myself) that AJV (and now @hyperjump/json-schema in this pr) is only used to validate the referenced schema.

i.e. If you have this YAML file called ./product.yaml open:

# yaml-language-server: $schema=./product.schema.json
productId:
  productId: 12

AJV/@hyperjump/json-schema will be used to validate ./product.schema.json, but not ./product.yaml

datho7561 avatar Sep 26 '25 18:09 datho7561

Hello everyone from the OpenAPI community 👋

We're currently leading an investigation as to why people are holding back migrating to OpenAPI 3.1/3.2, and the lack of support for JSON schema 2020-12 in a number of places seems to be one of the things holding people.

More context in this thread of the discussion

This pull request would be incredibly useful to move things forward, but it seems stalled? Would you mind sharing some more context? maybe we can help?

Thanks!

baywet avatar Dec 10 '25 20:12 baywet

Cc @jdesrosiers the maintainer of hyperjump

jeremyfiel avatar Dec 10 '25 21:12 jeremyfiel

Would you mind sharing some more context?

@baywet

This PR won't support validating YAML against a 2019-09 or 2020-12 JSON schema, which is probably what people want.

In order to properly validate the YAML against a 2019-09 or 2020-12 JSON schema, we will need to rewrite significant portions of this language server, since the code to validate the YAML against the JSON schema is in this repository and is not provided by an external dependency.

This PR supports validating the schema associated with a YAML file and reporting any errors in that schema. Once the wording of the README has been updated to reflect this and some proper test cases are added, I think this PR is good to merge. However, the original author of the PR hasn't responded to the review and I've been pretty busy with other stuff.

If folks think it's worth cleaning up this PR and getting it merged, let me know.

datho7561 avatar Dec 10 '25 22:12 datho7561

@datho7561 Thank you for the additional information!

Are there any plans/commitments to add support for 2020-12 in the language server from Red Hat/IBM at this stage? Is it safe to assumed that #856 is the correct issue to track that? For information, I had internal discussions with the team that owns the json language service, they are node code complete on support for 2020-12 yet, but getting there.

baywet avatar Dec 11 '25 13:12 baywet

Are there any plans/commitments to add support for 2020-12 in the language server from Red Hat/IBM at this stage?

Not really, it's just me working on the project part time from Red Hat/IBM and it seems like a pretty major time commitment. I could review a PR if someone contributes it.

Is it safe to assumed that https://github.com/redhat-developer/yaml-language-server/issues/856 is the correct issue to track that?

Yes, that seems like a good place to track it.

datho7561 avatar Dec 11 '25 15:12 datho7561

Yes, that seems like a good place to track it.

Alright, I'll follow up there to avoid side-tracking this PR.

baywet avatar Dec 11 '25 16:12 baywet

If @hyperjump/json-schema is useful for supporting 2020-12, let me know. I'd be happy to help if I can.

jdesrosiers avatar Dec 13 '25 14:12 jdesrosiers

@jdesrosiers thanks for joining the conversation! one of the question that was pending (I didn't get the time to research it) in #856 is this: would we be able to get precise location information from the lib so we can report the errors back to vscode?

baywet avatar Dec 15 '25 13:12 baywet