Skip to content

Support draft-04 schemas #1065

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

datho7561
Copy link
Contributor

What does this PR do?

This helps to support the schema for openapi 3.0.0, among others, that use an older draft of JSON schema that has some type differences that make it incompatible with JSON schema draft 07.

See #1006 , the root cause for the issues that PR caused is that some schemas reference the metaschema using https, eg. https://json-schema.org/draft-07/schema#, which is invalid according to the spec. This PR suppresses this error, because in practice many schemas use https for the metaschema reference, and that shouldn't prevent validation of the YAML document.

  • TODO: Instead, we should provide a warning letting the user know about the https issue in the schema so they can fix the schema or file an issue to get the schema fixed.

What issues does this PR fix or reference?

Fixes #780, Fixes #752

(and many, many duplicates we'll have to find and clean up)

Is it tested? How?

Unit test

@coveralls
Copy link

coveralls commented May 5, 2025

Coverage Status

coverage: 83.85% (+0.03%) from 83.824%
when pulling 0400d2a on datho7561:taking-my-own-stab-at-04
into 1be76fb on redhat-developer:main.

@datho7561
Copy link
Contributor Author

Adding the warning is much harder than I anticipated. We depend on vscode-json-languageservice and use some if its internal code. vscode-json-languageservice doesn't support reporting warnings on schemas until the next major version. A lot of the internals have changed, so by bumping vscode-json-languageservice, I prevent the extension from being able to compile.

This helps to support the schema for openapi 3.0.0,
among others, that use an older draft of JSON schema that has some type
differences that make it incompatible with JSON schema draft 07.

See redhat-developer#1006 , I think the root cause for the issues that PR caused
is that we were trying to download and cache the metaschema from
the "URL" instead of using the copy that's bundled with `ajv`.

Fixes redhat-developer#780, Fixes redhat-developer#752

(and many, many duplicates we'll have to find and clean up)

Signed-off-by: David Thompson <davthomp@redhat.com>
@datho7561 datho7561 force-pushed the taking-my-own-stab-at-04 branch from d4c0017 to 0400d2a Compare May 7, 2025 20:46
datho7561 added a commit to datho7561/yaml-language-server that referenced this pull request May 12, 2025
The primary motivation for doing this is to allow warnings to be
reported on schemas.
I would like to report warnings on schemas as a part of
redhat-developer#1065.

When updating the json language service,
there were many API changes that I needed to adapt to,
and some tests that I changed.

Notably, I needed to copy a lot of the implementation of
`JSONSchemaService` into our subclass of `JSONSchemaService`.
`JSONSchemaService` turns all schema identifiers into URIs and escapes all
`/` in the fragment,
and does this in the private `normalizeId` method that we can't override
Combined, these behaviours cause many tests to fail.

Closes redhat-developer#1069

Signed-off-by: David Thompson <davthomp@redhat.com>
@datho7561
Copy link
Contributor Author

See #1072 ; ideally we get that merged, then we can supply the warning through json-languageservice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants