Skip to content
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

Rejects schemas where $ref refers to $id or $anchor #823

Open
1 of 4 tasks
sam-mccall opened this issue Dec 28, 2022 · 2 comments
Open
1 of 4 tasks

Rejects schemas where $ref refers to $id or $anchor #823

sam-mccall opened this issue Dec 28, 2022 · 2 comments
Labels

Comments

@sam-mccall
Copy link

Describe the bug

When processing schemas, the server seems to assume that the hash part a $ref is always a JSON pointer.

Therefore the following schema can't be loaded, with an error $ref 'A' in 'file:///...' can not be resolved.

Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "properties": {
    "A": { "$id": "#A", "type": "string" },
    "B": { "$ref": "#A" }
  }
}

Example valid doc:

# yaml-language-server: $schema=fail.schema.json
A: foo
B: bar

Expected Behavior

Schema loads and document validates correctly.

The draft-07 spec says:

Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by "$id".

and goes on to give a very similar example.

Current Behavior

Language server shows the error: $ref 'A' in 'file:///...' can not be resolved.

For the 2019 JSON-schema spec, we should use "$anchor": "A" instead of "$id": "#A"`. This also doesn't work.

Using a JSON-pointer link "$ref": "/properties/A" does work.

Steps to Reproduce

  1. Save the files above as fail.schema.json and fail.yaml
  2. Open fail.yaml in an editor talking to yaml-language-server
  3. See spurious diagnostics on the first line of content

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)
@sam-mccall
Copy link
Author

Browsing the code findSection() looks suspicious: it seems ids/anchors would have to be handled somewhere near there, rather than just assuming the hash fragment is a JSON pointer.

@gorkem
Copy link
Collaborator

gorkem commented Mar 26, 2023

We are using vscode-json-langaugeservice to resolve schemas. This has been fixed upstream, we probably need to adjust to this later version.

remcohaszing added a commit to remcohaszing/schemastore that referenced this issue Mar 27, 2023
remcohaszing added a commit to remcohaszing/schemastore that referenced this issue Mar 27, 2023
@gorkem gorkem self-assigned this Apr 5, 2023
@gorkem gorkem removed their assignment May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants