json-schema-org / json-schema-org/website
🐛 Bug:Scopes.tscurrentlygenerateSchemaScopes` fails to resolve nested constructs — incomplete scope mapping
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 169
- Forks
- 484
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 6
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.
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
Start by reading lib/getScopesOfParsedJsonSchema.ts and tracing its current scope output for the provided schema. Add unit tests for combinators, local $ref resolution, tuple items, patternProperties, additionalProperties, and circular references, then implement the recursive traversal and verify deterministic, de-duplicated scopes plus termination for circular refs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100