Skip to content

๐Ÿ› Bug:Scopes.tscurrentlygenerateSchemaScopes` fails to resolve nested constructs โ€” incomplete scope mappingย #2174

@Adityakk9031

Description

@Adityakk9031

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 is lib/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 #/definitions or #/$defs).
  • Traverse combinators: oneOf, anyOf, allOf, not.
  • Iterate definitions / $defs or nested schemas inside them.
  • Handle tuple array schemas (items as an array), prefixItems, additionalItems, or contains.
  • Traverse patternProperties or additionalProperties when they are schemas.
  • Walk conditional schemas (if / then / else) or dependentSchemas.

As a result, many valid JSONPaths that should receive a scope are omitted from output.


Repro (minimal)

  1. 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 $ref pointers (#/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]). For allOf emit 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, and emitScope.
  • Maintain deterministic ordering and de-duplication of emitted scopes.
  • Add unit tests for combinators, $ref resolution, tuple items, patternProperties, additionalProperties, and circular $ref termination.

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

  1. Implement the recursive walker in lib/getScopesOfParsedJsonSchema.ts (or refactor into lib/schemaWalker.ts and export a wrapper).
  2. Add unit tests covering the example schema and other keywords (combinators, refs, tuple items, patternProperties).
  3. Add a short ADR documenting $ref resolution rules (local-only) and allOf merging semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is the initial status for an issue that requires triage.๐Ÿ› BugIndicates that the issue is a bug or defect.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions