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

Merged

Conversation

datho7561
Copy link
Contributor

@datho7561 datho7561 commented May 5, 2025

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. I feel like we should do this in a separate PR, later, since it's complex (see #1065 (comment)).

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: 84.051% (+0.1%) from 83.921%
when pulling 8a9f70a on datho7561:taking-my-own-stab-at-04
into 4370b5c 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.

@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 <[email protected]>
@datho7561
Copy link
Contributor Author

datho7561 commented May 12, 2025

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

IMO, it makes more sense to get this merged first. This PR fixes a real problem. That PR is risky at best; we are playing around with a lot of internals of the json-languageservice and I don't think I have a strong enough grasp on this code base to not have messed something up.

@datho7561 datho7561 force-pushed the taking-my-own-stab-at-04 branch from 0400d2a to de77c69 Compare May 22, 2025 20:38
@datho7561 datho7561 marked this pull request as ready for review May 22, 2025 20:47
@datho7561
Copy link
Contributor Author

@Davidonium if you have some time, could you please let me know what you think of this PR?

@Davidonium
Copy link
Contributor

@Davidonium if you have some time, could you please let me know what you think of this PR?

Sure thing, I will grab a look tomorrow

@datho7561 datho7561 force-pushed the taking-my-own-stab-at-04 branch from de77c69 to 12ea8a5 Compare May 26, 2025 12:59
@datho7561 datho7561 requested a review from Davidonium May 26, 2025 13:01
@datho7561
Copy link
Contributor Author

@msivasubramaniaan if you have a time, could you also please take a look at this?

@datho7561 datho7561 moved this to Pending review in Java Tooling Jun 12, 2025
@Ralmryr
Copy link

Ralmryr commented Jun 17, 2025

Bump! :)

@msivasubramaniaan
Copy link
Contributor

@datho7561 please confirm that redhat-developer/vscode-yaml#1100 should work with this fix

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 <[email protected]>
@datho7561 datho7561 force-pushed the taking-my-own-stab-at-04 branch from 12ea8a5 to 8a9f70a Compare June 17, 2025 13:16
@datho7561
Copy link
Contributor Author

@msivasubramaniaan I made sure that redhat-developer/vscode-yaml#1100 works with this fix, and added a test case for https://json-schema.org/draft-04/schema#

Copy link
Contributor

@msivasubramaniaan msivasubramaniaan left a comment

Choose a reason for hiding this comment

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

@datho7561 thanks for the fix. It works on both HTTP and HTTPS

@msivasubramaniaan msivasubramaniaan merged commit fce910a into redhat-developer:main Jun 17, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this from Pending review to Done in Java Tooling Jun 17, 2025
@datho7561 datho7561 deleted the taking-my-own-stab-at-04 branch June 17, 2025 13:28
@Ralmryr
Copy link

Ralmryr commented Jun 17, 2025

Amazing work from developers! Do you have a rough idea of the next release date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

YAML Language Server checks against JSON Schema Draft 7 instead of the defined one OpenAPI 3.0.0 specification is treated as invalid
5 participants