or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-3/

Schema Parent Tracker

Build a utility that tracks and reports parent-child relationships in JSON Schema documents.

Requirements

Create a tool that analyzes a JSON Schema and generates a report showing the hierarchical relationships between schema objects. For each schema object that has a parent, the report should include:

  • The JSON Pointer path to the schema
  • The JSON Pointer path to its parent schema
  • The keyword that contains the schema (e.g., "properties", "items", "allOf")
  • The property name or array index within that keyword

The root schema has no parent and should not be included in the report.

Input

Your tool should accept a JSON Schema object as input.

Output

Return an array of relationship objects, where each object contains:

  • path: JSON Pointer to the child schema
  • parentPath: JSON Pointer to the parent schema
  • keyword: The keyword containing this schema
  • key: The property name (string) or array index (number)

Sort the results by path alphabetically.

Example

Given this schema:

{
  properties: {
    user: {
      type: 'object',
      properties: {
        name: { type: 'string' }
      }
    }
  },
  allOf: [
    { type: 'object' },
    { required: ['user'] }
  ]
}

Expected output:

[
  {
    path: '/allOf/0',
    parentPath: '',
    keyword: 'allOf',
    key: 0
  },
  {
    path: '/allOf/1',
    parentPath: '',
    keyword: 'allOf',
    key: 1
  },
  {
    path: '/properties/user',
    parentPath: '',
    keyword: 'properties',
    key: 'user'
  },
  {
    path: '/properties/user/properties/name',
    parentPath: '/properties/user',
    keyword: 'properties',
    key: 'name'
  }
]

Test Cases

  • It returns an empty array for a root-only schema with no nested schemas @test
  • It correctly tracks parent-child relationships for schemas nested in properties @test
  • It correctly tracks parent-child relationships for schemas nested in array keywords like allOf @test
  • It correctly identifies the keyword and key for each relationship @test

Implementation

@generates

API

/**
 * Analyzes a JSON Schema and returns parent-child relationships.
 *
 * @param {object} schema - The JSON Schema to analyze
 * @returns {Array<{path: string, parentPath: string, keyword: string, key: string|number}>}
 *          Array of relationship objects sorted by path
 */
function trackSchemaParents(schema) {
  // IMPLEMENTATION HERE
}

module.exports = { trackSchemaParents };

Dependencies { .dependencies }

json-schema-traverse { .dependency }

Provides JSON Schema traversal with parent tracking capabilities.