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

[json] Local JSON schemas should find each other based on their id fields #139752

Open
mitar opened this issue Dec 25, 2021 · 2 comments
Open

[json] Local JSON schemas should find each other based on their id fields #139752

mitar opened this issue Dec 25, 2021 · 2 comments
Assignees
Labels
feature-request Request for new features or functionality json JSON support issues
Milestone

Comments

@mitar
Copy link

mitar commented Dec 25, 2021

I have a JSON schema which looks like:

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "https://example.com/item.json",
  "allOf": [{
    "$ref": "https://example.com/definitions.json#/$defs/object"
  }]
}
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "https://example.com/definitions.json",
  "$defs": {
    "object": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        }
      }
    }
  }
}

I would like that I would be able to edit them in VSCode with all $refs resolving to their local counterparts. This can be done by VSCode parsing $id field and determining the mapping from the remote URL to local file based on $id.

@aeschli aeschli added json JSON support issues feature-request Request for new features or functionality labels Jan 2, 2022
@aeschli aeschli added this to the Backlog milestone Jan 2, 2022
@aeschli aeschli changed the title Local JSON schemas should find each other based on their id fields [json] Local JSON schemas should find each other based on their id fields Jan 2, 2022
@JacobRuby
Copy link

Looking for this as well. I have a repository of schemas and documents using those schemas, except they're organized into file structures. This means whenever I go another folder deeper into my documents, I have to add a ../ to the $schema and $refs in my document to reference the same local file. It would be nice to have all schemas in a workspace loaded to a list by their $ids that you can auto-complete when you start typing in your domain name in a $ref or $schema.

@njakob
Copy link

njakob commented Sep 30, 2023

I'm also looking for a simple solution for my JSON schemas to be resolved locally and I wanted to collect my findings.

It was suggested in a related issue (#174672) to use the json.schemas setting with the file:// protocol. However, I didn't manage to have VSCode load the correct schema when trying to reference a relative file since:

  1. Relative paths are not possible with a file:// protocol
  2. Using ${workspaceFolder} is not possible within schema references ([json] $schema: support predefined variables like ${workspaceFolder} #166438)
  3. Using relative paths directly will simply be appended to the HTTPS URI (I'm not sure if this is an expected behavior)

As a note, it is possible to use fileMatch field but requires a specific path naming convention which is not always desired.

Resolving all schema by IDs as suggested by this issue would be the simplest! An alternative could be to go in the direction suggested by #166438 and leverage the $ref field within the json.schemas configuration field.

{
    "json.schemas": [
        {
            "url": "https://example.com/item.json",
            "schema": {
                "$ref": "file://${workspaceFolder}/schemas/items.json"
            }
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality json JSON support issues
Projects
None yet
Development

No branches or pull requests

4 participants