evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a TypeScript utility that validates and analyzes JSON Schema definitions using type-safe structures.
Create a module that provides functions to work with JSON Schema definitions. The module should:
Schema Validation Check: Implement a function isValidSchema that accepts a schema object and returns a boolean indicating whether it represents a valid schema structure. A valid schema must have at least one of: type, properties, items, allOf, anyOf, oneOf, or $ref.
Required Fields Extraction: Implement a function getRequiredFields that accepts a schema object and returns an array of required field names. If the schema has no required fields, return an empty array.
Schema Complexity Analyzer: Implement a function analyzeComplexity that accepts a schema object and returns an object with complexity metrics:
hasNestedObjects: boolean indicating if the schema has nested object propertieshasArrays: boolean indicating if the schema defines arrayshasComposition: boolean indicating if the schema uses composition keywords (allOf, anyOf, oneOf)constraintCount: number of validation constraints applied (e.g., minLength, maxLength, pattern, minimum, maximum, enum)Property Type Checker: Implement a function getPropertyType that accepts a schema object and a property name, and returns the type of that property as a string. If the property doesn't exist, return null. If the type is an array of types, return the first type.
isValidSchema returns true for a schema with a type property set to "string" @testisValidSchema returns true for a schema with properties defined but no type @testisValidSchema returns false for an empty object with no schema keywords @testgetRequiredFields returns ["name", "email"] for a schema with required: ["name", "email"] @testgetRequiredFields returns an empty array for a schema with no required property @testanalyzeComplexity correctly identifies a schema with nested object properties @testanalyzeComplexity correctly counts validation constraints including minLength, pattern, and enum @testgetPropertyType returns "string" for a property defined with type: "string" @testgetPropertyType returns null for a non-existent property @test/**
* Checks if a schema object is a valid schema structure
*/
export function isValidSchema(schema: any): boolean;
/**
* Extracts required field names from a schema
*/
export function getRequiredFields(schema: any): string[];
/**
* Analyzes the complexity of a schema
*/
export function analyzeComplexity(schema: any): {
hasNestedObjects: boolean;
hasArrays: boolean;
hasComposition: boolean;
constraintCount: number;
};
/**
* Gets the type of a specific property in a schema
*/
export function getPropertyType(schema: any, propertyName: string): string | null;Provides TypeScript type definitions for JSON Schema structures.