docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
A utility that analyzes JSON Schema documents and collects information about all schema objects within them.
Build a tool that traverses a JSON Schema document and collects all schema objects into an array. The tool should visit every schema object in the document, including nested schemas within properties, items, definitions, and other schema-containing keywords.
{properties: {name: {type: 'string'}, age: {type: 'number'}}}, the tool returns an array containing 3 schema objects: the root schema, the name schema, and the age schema @test{}, the tool returns an array with only the root schema object @testExtend the tool to filter and collect only schemas of a specific type. The tool should traverse the entire schema document and return only those schema objects that match a given type.
'string' types, the tool returns only schema objects where type === 'string' @test/**
* Collects all schema objects from a JSON Schema document.
*
* @param {object} schema - The JSON Schema document to analyze.
* @returns {Array<object>} An array of all schema objects found in the document.
*/
function collectSchemas(schema) {
// IMPLEMENTATION HERE
}
/**
* Collects schema objects of a specific type from a JSON Schema document.
*
* @param {object} schema - The JSON Schema document to analyze.
* @param {string} typeFilter - The type to filter for (e.g., 'string', 'number', 'object').
* @returns {Array<object>} An array of schema objects matching the specified type.
*/
function collectSchemasByType(schema, typeFilter) {
// IMPLEMENTATION HERE
}
module.exports = {
collectSchemas,
collectSchemasByType
};Provides schema traversal functionality for visiting all schema objects in a JSON Schema document.