or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-5/

Schema Array Keyword Analyzer

Build a JSON Schema analyzer that extracts and reports information about schemas contained within array keywords (allOf, anyOf, oneOf).

Requirements

Create a function analyzeArrayKeywords that accepts a JSON Schema and returns a structured report containing:

  1. Total counts - Count how many times each array keyword appears in the schema (allOf, anyOf, oneOf)
  2. Schema details - For each occurrence of these keywords, collect the schemas contained within them along with their locations

The function should return an object with this structure:

{
  counts: {
    allOf: <number>,
    anyOf: <number>,
    oneOf: <number>
  },
  schemas: [
    {
      keyword: <string>,        // 'allOf', 'anyOf', or 'oneOf'
      path: <string>,           // JSON Pointer to the array keyword
      index: <number>,          // Index of the schema within the array
      schema: <object>          // The actual schema object
    },
    // ... more entries
  ]
}

The schemas array should be ordered by the traversal order of the schemas (pre-order, depth-first).

Constraints

  • Only count and collect schemas from allOf, anyOf, and oneOf keywords
  • Do not resolve $ref references
  • Handle deeply nested schemas correctly
  • The path field should be the JSON Pointer to the parent array keyword (not to the individual schema)

Examples

Example 1: Simple allOf

Input schema:

{
  allOf: [
    { type: 'string' },
    { minLength: 5 }
  ]
}

Expected output:

{
  counts: { allOf: 1, anyOf: 0, oneOf: 0 },
  schemas: [
    { keyword: 'allOf', path: '/allOf', index: 0, schema: { type: 'string' } },
    { keyword: 'allOf', path: '/allOf', index: 1, schema: { minLength: 5 } }
  ]
}

Example 2: Nested array keywords

Input schema:

{
  properties: {
    foo: {
      anyOf: [
        { type: 'string' },
        { type: 'number' }
      ]
    }
  },
  allOf: [
    { required: ['foo'] }
  ]
}

Expected output:

{
  counts: { allOf: 1, anyOf: 1, oneOf: 0 },
  schemas: [
    { keyword: 'anyOf', path: '/properties/foo/anyOf', index: 0, schema: { type: 'string' } },
    { keyword: 'anyOf', path: '/properties/foo/anyOf', index: 1, schema: { type: 'number' } },
    { keyword: 'allOf', path: '/allOf', index: 0, schema: { required: ['foo'] } }
  ]
}

Example 3: Empty schema

Input schema:

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

Expected output:

{
  counts: { allOf: 0, anyOf: 0, oneOf: 0 },
  schemas: []
}

Tests

  • It correctly counts allOf occurrences @test
  • It correctly counts anyOf occurrences @test
  • It correctly counts oneOf occurrences @test
  • It extracts schemas from allOf with correct paths and indices @test
  • It extracts schemas from anyOf with correct paths and indices @test
  • It extracts schemas from oneOf with correct paths and indices @test
  • It handles nested array keywords correctly @test
  • It returns empty results for schemas without array keywords @test

@generates

API

/**
 * Analyzes a JSON Schema and extracts information about schemas
 * contained within array keywords (allOf, anyOf, oneOf).
 *
 * @param {object} schema - The JSON Schema to analyze
 * @returns {object} Analysis results with counts and schema details
 */
function analyzeArrayKeywords(schema) {
  // IMPLEMENTATION HERE
}

module.exports = { analyzeArrayKeywords };

Dependencies { .dependencies }

json-schema-traverse { .dependency }

Provides JSON Schema traversal functionality for visiting schema objects and extracting contextual information.