or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-7/

JSON Schema Traversal Analyzer

Overview

Build a tool that analyzes JSON Schema documents and records the traversal order of schema objects. The tool should track when each schema is visited (entry) and when processing of that schema completes (exit), providing insights into the structure of the schema document.

Requirements

Traversal Tracking

Your tool should traverse a JSON Schema document and record:

  1. Entry events: When a schema object is first visited, record its JSON Pointer path
  2. Exit events: When a schema object's processing completes (after all children are processed), record its JSON Pointer path
  3. Count statistics: Total number of schema objects visited

For example, given this simple schema:

{
  "type": "object",
  "properties": {
    "name": {"type": "string"}
  }
}

The traversal should produce:

  • Entry at: "" (root)
  • Entry at: /properties/name
  • Exit at: /properties/name
  • Exit at: "" (root)

Notice that for each schema, the exit event occurs after all its child schemas have been fully processed.

Output Format

The tool should export an analyzeSchemaTraversal(schema) function that returns an object with:

  • entries: Array of JSON Pointer strings in entry order
  • exits: Array of JSON Pointer strings in exit order
  • totalSchemas: Number indicating total schemas visited

JSON Pointer paths should follow RFC 6901 format (e.g., /properties/name, with empty string "" for root).

Implementation File

Create your implementation in src/schema-depth-analyzer.js.

Dependencies { .dependencies }

json-schema-traverse { .dependency }

Provides JSON Schema traversal capabilities.

Test Cases

Create test cases in src/schema-depth-analyzer.test.js.

Test 1: Simple Schema @test

Input:

const schema = {
  type: "object",
  properties: {
    foo: {type: "string"}
  }
};

Expected behavior:

  • entries array should contain: ["", "/properties/foo"]
  • exits array should contain: ["/properties/foo", ""]
  • totalSchemas should be 2
  • Exit for /properties/foo should appear before exit for root

Test 2: Nested Schemas @test

Input:

const schema = {
  properties: {
    user: {
      properties: {
        name: {type: "string"}
      }
    }
  }
};

Expected behavior:

  • Should record entries for root, /properties/user, and /properties/user/properties/name
  • Exits should appear in reverse order compared to entries
  • totalSchemas should equal the number of entries
  • Each JSON pointer in entries should appear exactly once in exits

Test 3: Multiple Children @test

Input:

const schema = {
  allOf: [
    {type: "string"},
    {type: "number"}
  ]
};

Expected behavior:

  • Should visit root first, then both array elements
  • Both /allOf/0 and /allOf/1 should appear in entries
  • Root exit should be last in the exits array
  • Entry and exit arrays should have the same length

Constraints

  • The tool should work with any valid JSON Schema structure
  • Do not resolve $ref references
  • Track depth accurately regardless of nesting complexity
  • Handle standard JSON Schema keywords (properties, items, allOf, anyOf, oneOf, etc.)