docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
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.
Your tool should traverse a JSON Schema document and record:
For example, given this simple schema:
{
"type": "object",
"properties": {
"name": {"type": "string"}
}
}The traversal should produce:
"" (root)/properties/name/properties/name"" (root)Notice that for each schema, the exit event occurs after all its child schemas have been fully processed.
The tool should export an analyzeSchemaTraversal(schema) function that returns an object with:
entries: Array of JSON Pointer strings in entry orderexits: Array of JSON Pointer strings in exit ordertotalSchemas: Number indicating total schemas visitedJSON Pointer paths should follow RFC 6901 format (e.g., /properties/name, with empty string "" for root).
Create your implementation in src/schema-depth-analyzer.js.
Provides JSON Schema traversal capabilities.
Create test cases in src/schema-depth-analyzer.test.js.
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/properties/foo should appear before exit for rootInput:
const schema = {
properties: {
user: {
properties: {
name: {type: "string"}
}
}
}
};Expected behavior:
/properties/user, and /properties/user/properties/nametotalSchemas should equal the number of entriesentries should appear exactly once in exitsInput:
const schema = {
allOf: [
{type: "string"},
{type: "number"}
]
};Expected behavior:
/allOf/0 and /allOf/1 should appear in entries$ref referencesproperties, items, allOf, anyOf, oneOf, etc.)