Skip to content

Fix handling of absolute local schema paths from yaml.schemas and yaml/get/jsonSchema StackOverflow#1260

Merged
datho7561 merged 7 commits into
redhat-developer:mainfrom
shin19991207:fix-1249
May 25, 2026
Merged

Fix handling of absolute local schema paths from yaml.schemas and yaml/get/jsonSchema StackOverflow#1260
datho7561 merged 7 commits into
redhat-developer:mainfrom
shin19991207:fix-1249

Conversation

@shin19991207
Copy link
Copy Markdown
Member

@shin19991207 shin19991207 commented May 21, 2026

What does this PR do?

  1. Fixed handling of absolute local schema paths from yaml.schemas

    When multiple schemas with absolute local paths matched the same YAML file, the paths were kept as plain filesystem paths instead of being normalized to file:// URIs before schema registration.

    This causes problem when a YAML file matches multiple schemas:

    • yaml-language-server combines those schemas internally as schemaservice://combinedSchema/...
    • because the schema paths were not normalized first, the combined-schema resolution resolved each absolute local schema path /Users/.../schema.json against the internal schemaservice://combinedSchema/... URI, producing invalid references like schemaservice:///.../schema.json
    • schema loading failed with Unable to load schema from 'schemaservice:///...': No content.

    This PR fixes normalizes absolute local paths from yaml.schemas to file:// URIs before schema registration. This ensures schema registration uses the correct local file URI, so schema validation and schema selection (schema picker) works properly.

  2. Fixed yaml/get/jsonSchema StackOverflow

    The problem was that the schema picker (status bar) in vscode-yaml calls yaml/get/jsonSchema only wanting to get schema metadata such as schema URI, name, description, and versions. However, the yaml/get/jsonSchema handler in YLS was using the full schema resolution path through the getSchemaForResource(). Since this path is intended for validation, it can resolve combined schemas and walk complex $ref graphs. When a YAML file matched multiple "large" or "complex" schemas, the metadata request could end up doing deep schema resolution just to render the UI, which could cause a StackOverflow:

    [Trace - 3:22:55 PM] Received response 'yaml/get/jsonSchema - (153)' in 22ms.
    Request failed: Request yaml/get/jsonSchema failed with message: Maximum call stack size exceeded (-32603).
    

    Since yaml/get/jsonSchema is used for schema status UI and only needs display metadata for the schemas associated with the current YAML doc, this PR adds a lightweight lookup path for that request to return metadata only without fully resolving the schemas.

What issues does this PR fix or reference?

Fixes redhat-developer/vscode-yaml#1249
Related to redhat-developer/vscode-yaml#1253

Is it tested? How?

  • New automated tests
  • Manual testing

To verify absolute local paths from yaml.schemas is registered correctly:

  1. Map two or more JSON schemas with absolute local paths to the same YAML file:
"yaml.schemas": {
  "/Users/.../schema1.json": "/Users/.../asdf.yaml",
  "/Users/.../schema2.json": "/Users/.../asdf.yaml"
}
  1. Go to /Users/.../asdf.yaml. Verify validation works and no error appears like Problems loading reference 'schemaservice:///...': Unable to load schema from 'schemaservice:///...': No content..
  2. Open the schema picker from Multiple JSON Schemas, verify the schemas are shown as file:///... URIs, not schemaservice:///... URIs.

To verify yaml/get/jsonSchema does not cause StackOverflow:

  1. Map multiple "large" JSON schemas to the same YAML file, e.g.:
"yaml.schemas": {
      "https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/alpha/azure.yaml.json": "/Users/.../asdf.yaml",
      "https://www.schemastore.org/sourcehut-build-0.65.0.json": "/Users/.../asdf.yaml"
}
  1. Open the schema picker, verify that there's no error appears like [Trace - 3:22:55 PM] Received response 'yaml/get/jsonSchema - (153)' in 22ms. Request failed: Request yaml/get/jsonSchema failed with message: Maximum call stack size exceeded (-32603).

Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
@shin19991207 shin19991207 changed the title Fix handling of absolute local schema paths from yaml.schemas Fix handling of absolute local schema paths from yaml.schemas and yaml/get/jsonSchema StackOverflow May 22, 2026
@shin19991207 shin19991207 marked this pull request as ready for review May 22, 2026 18:10
@shin19991207 shin19991207 requested a review from datho7561 as a code owner May 22, 2026 18:10
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks, Morgan!

@datho7561 datho7561 merged commit d770d7f into redhat-developer:main May 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StackOverflow in yls when trying to open the schema picker for a file with multiple schemas

2 participants