docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility that analyzes JSON Schema documents to collect and categorize all the standard JSON Schema keywords found within them.
Your task is to implement a function that traverses a JSON Schema document and returns a categorized report of all standard JSON Schema keywords present in the schema and its nested subschemas.
The function should:
singleSchemaKeywords: Array of keywords that contain a single schema (e.g., "not", "additionalProperties", "if", "then", "else")arraySchemaKeywords: Array of keywords that contain arrays of schemas (e.g., "allOf", "anyOf", "oneOf")objectSchemaKeywords: Array of keywords that contain objects of schemas (e.g., "properties", "patternProperties", "definitions")totalSchemasVisited: Total count of schema objects visited during traversalEach keyword should only appear once in its respective category, even if it appears multiple times in the schema.
Given this schema:
{
properties: {
name: { type: 'string' },
age: { type: 'number' }
},
allOf: [
{ type: 'object' },
{ required: ['name'] }
],
if: { properties: { age: { minimum: 18 } } },
then: { properties: { canVote: { const: true } } }
}The output should be:
{
singleSchemaKeywords: ['if', 'then'],
arraySchemaKeywords: ['allOf'],
objectSchemaKeywords: ['properties'],
totalSchemasVisited: 8
}Given a schema with properties containing two properties, the function returns objectSchemaKeywords containing "properties" and totalSchemasVisited of 3 @test
Given a schema with allOf, anyOf, and oneOf keywords, the function returns arraySchemaKeywords containing all three keywords @test
Given a schema with if, then, and else keywords, the function returns singleSchemaKeywords containing all three keywords @test
Given a schema with definitions and nested patternProperties, the function returns objectSchemaKeywords containing both keywords @test
Given an empty schema object, the function returns empty arrays for all keyword categories and totalSchemasVisited of 1 @test
/**
* Analyzes a JSON Schema and returns categorized keywords found within it.
*
* @param {object} schema - The JSON Schema to analyze
* @returns {object} Analysis result with categorized keywords and visit count
* @returns {string[]} returns.singleSchemaKeywords - Keywords containing single schemas
* @returns {string[]} returns.arraySchemaKeywords - Keywords containing schema arrays
* @returns {string[]} returns.objectSchemaKeywords - Keywords containing schema objects
* @returns {number} returns.totalSchemasVisited - Total schemas visited during traversal
*/
function analyzeSchemaKeywords(schema) {
// IMPLEMENTATION HERE
}
module.exports = { analyzeSchemaKeywords };Provides JSON Schema traversal capabilities for visiting all schema objects.