redhat-developer / redhat-developer/vscode-yaml
Feature Request: Add Support for $id-Based Schema Resolution
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 830
- Forks
- 260
- Avg merge
- 5h 43m
- Merged PRs (30d)
- 1
Description
Is your enhancement related to a problem? Please describe.
The YAML extension currently resolves $ref paths relative to the base URL of the parent schema, without considering the $id field as a unique identifier. This creates issues when:
- Relative
$refpaths don't align with the actual hosting or file structure of the schema files. - The schema references are expected to be resolved using their
$id, as supported by tools like AJV.
For example:
$schema: "https://example.com/survey/types/root.schema.json"
type: object
properties:
config:
$ref: "/survey/types/modelconfig.schema.json"
The schema at /survey/types/modelconfig.schema.json includes:
{
"$id": "/survey/types/modelconfig.schema.json",
"type": "object",
"properties": {
"example": { "type": "string" }
}
}
VSCode tries to resolve /survey/types/modelconfig.schema.json relative to the base URL but fails if the file is not accessible at that exact path, even though the schema has a valid $id. This leads to schema resolution errors and breaks workflows involving interdependent schemas.
Describe the solution you would like
The YAML extension should support $id-based schema resolution in addition to the current relative path resolution. Specifically:
- When encountering a
$ref, the extension should:- First, attempt to resolve it relative to the base URL (current behavior).
- If resolution fails, look for a schema in a registry that matches the
$idspecified in the referenced schema.
- Implement a schema registry to preload or dynamically cache schemas by
$idfor efficient resolution.
This approach aligns with the JSON Schema specification and ensures compatibility with tools like AJV.
Describe alternatives you have considered
-
Manual Schema Mapping: Use the
yaml.schemassetting to manually map schemas to files or URLs. This works but is error-prone and scales poorly for large or dynamic schema setups.
Example:"yaml.schemas": { "./schemas/modelconfig.schema.json": "*.yaml" } -
Inline Definitions: Refactor schemas to use
$defsand reference them with#paths. This resolves the issue in VSCode but breaks compatibility with tools like AJV, which are essential for CI/CD workflows. -
Flatten Schemas: Merge schemas into a single file to avoid external references. This is infeasible for large projects with shared schema components.
Additional context
This enhancement would improve compatibility with the JSON Schema specification, where $id is treated as a unique identifier for schemas. It would also make the YAML extension more robust for advanced workflows.
References
Example Use Case
In our setup, schemas are referenced by $ref paths but rely on $id for resolution. While tools like AJV handle this setup correctly, the VSCode YAML extension fails to resolve these references, making it challenging to use in development workflows.
Environment:
- VSCode Version: 1.96.2
- YAML Extension Version: 1.15.0
- JSON Schema Draft: 07
- Operating System: MacOS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files, tests, or entry points are named. Start by locating the existing relative $ref resolution path, then investigate how schemas are loaded and cached; done means failed base-URL resolution can find a referenced schema by its $id without breaking current resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100