-
-
Notifications
You must be signed in to change notification settings - Fork 419
Description
Short description
getScopesOfParsedJsonSchema fails to recursively traverse and generate scopes for many common JSON Schema constructs (combinators, $ref, definitions/$defs, array tuple schemas, patternProperties, additionalProperties, etc.). This results in missing schema scopes and broken downstream features such as clickable documentation links and syntax highlighting in the JSON Editor.
Affected file
lib/getScopesOfParsedJsonSchema.ts
The originally reported path (
website/lib/generateSchemaScopes.ts) was incorrect โ the utility to update islib/getScopesOfParsedJsonSchema.ts.
Problem
The current implementation only processes shallow, top-level properties and items for type: 'object' or type: 'array'. It does not:
- Resolve and traverse
$ref(local#/definitionsor#/$defs). - Traverse combinators:
oneOf,anyOf,allOf,not. - Iterate
definitions/$defsor nested schemas inside them. - Handle tuple array schemas (
itemsas an array),prefixItems,additionalItems, orcontains. - Traverse
patternPropertiesoradditionalPropertieswhen they are schemas. - Walk conditional schemas (
if/then/else) ordependentSchemas.
As a result, many valid JSONPaths that should receive a scope are omitted from output.
Repro (minimal)
- Parse the following schema and call
getScopesOfParsedJsonSchema(parsedSchema).
{
"type": "object",
"properties": {
"title": { "type": "string" },
"meta": {
"anyOf": [
{
"type": "object",
"properties": {
"published": { "type": "boolean" }
}
},
{ "$ref": "#/definitions/authorInfo" }
]
}
},
"definitions": {
"authorInfo": {
"type": "object",
"properties": { "name": { "type": "string" } }
}
}
}Actual output (example)
Only top-level scopes are produced, e.g. "$" and "$['properties']['title']" โ meta.published and meta.name are missing.
Expected output (high level)
Scopes should include branches inside anyOf and the resolved $ref โ i.e. meta.published and meta.name.
Root cause
Traversal logic is typeโbased and shallow. It fails to treat schema keywords that can contain nested schemas, and it does not resolve or inline $ref targets for traversal.
Suggested fix
Replace the shallow walker with a recursive schema walker that:
- Emits a scope for the current schema node when appropriate.
- Resolves local
$refpointers (#/definitions/...and#/$defs/...) and traverses the resolved schema while preventing infinite recursion via a visited-set. - Traverses combinators (
oneOf,anyOf,allOf,not) by iterating their subschemas and adding branch-aware jsonPaths (e.g.['anyOf', index]). ForallOfemit scopes for each constituent and optionally provide metadata for later merge logic. - Processes object-like fields:
properties,patternProperties,additionalProperties,propertyNames,dependentSchemas. - Processes array-like fields:
items(single schema or tuple array),prefixItems,additionalItems,contains. - Processes conditional keywords:
if,then,else.
Implementation notes:
- Create helpers:
resolveRef,processObjectProperties,processSchemasArray, andemitScope. - Maintain deterministic ordering and de-duplication of emitted scopes.
- Add unit tests for combinators,
$refresolution, tupleitems,patternProperties,additionalProperties, and circular$reftermination.
Impact
- Fixes incomplete scope generation across real-world schemas.
- Restores clickable docs and correct syntax highlighting in the JSON Editor.
- Backwards-compatible (additive) but tests should verify downstream behavior where consumers previously relied on missing scopes.
Recommended next steps
- Implement the recursive walker in
lib/getScopesOfParsedJsonSchema.ts(or refactor intolib/schemaWalker.tsand export a wrapper). - Add unit tests covering the example schema and other keywords (combinators, refs, tuple
items,patternProperties). - Add a short ADR documenting $ref resolution rules (local-only) and
allOfmerging semantics.