docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a JSON Schema analyzer that extracts and reports information about schemas contained within array keywords (allOf, anyOf, oneOf).
Create a function analyzeArrayKeywords that accepts a JSON Schema and returns a structured report containing:
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).
allOf, anyOf, and oneOf keywords$ref referencespath field should be the JSON Pointer to the parent array keyword (not to the individual schema)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 } }
]
}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'] } }
]
}Input schema:
{
type: 'object',
properties: {
name: { type: 'string' }
}
}Expected output:
{
counts: { allOf: 0, anyOf: 0, oneOf: 0 },
schemas: []
}/**
* 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 };Provides JSON Schema traversal functionality for visiting schema objects and extracting contextual information.