UNPKG

@firefliesai/schema-forge

Version:

Transform TypeScript classes into JSON Schema definitions with automatic support for OpenAI, Anthropic, and Google Gemini function calling (tool) formats

56 lines (55 loc) 2.08 kB
/** * Class-validator integration for schema-forge * * This module provides utilities to infer JSON Schema properties from class-validator decorators. */ /** * JSON Schema items definition for array elements */ export interface InferredArrayItems { type?: 'string' | 'number' | 'integer' | 'boolean'; enum?: (string | number | boolean)[]; minimum?: number; maximum?: number; minLength?: number; maxLength?: number; format?: string; } /** * Interface for inferred JSON Schema properties from class-validator */ export interface InferredSchemaProperties { /** When true, property is inferred as array type from @IsArray or array decorators */ isArray?: boolean; /** Inferred schema for array items (from @ArrayContains, or each: true validators) */ items?: InferredArrayItems; maxItems?: number; minItems?: number; uniqueItems?: boolean; maximum?: number; minimum?: number; type?: 'integer' | 'string' | 'number' | 'array'; minLength?: number; maxLength?: number; format?: string; } /** * Infers JSON Schema properties from class-validator decorators * * Supported decorators: * - IsArray -> isArray: true, type: 'array' * - ArrayMaxSize -> maxItems * - ArrayMinSize -> minItems * - ArrayUnique -> uniqueItems: true * - ArrayNotEmpty -> minItems: 1 * - ArrayContains -> items.enum (when values are primitive) * - Max -> maximum (for numbers) or items.maximum (with each: true) * - Min -> minimum (for numbers) or items.minimum (with each: true) * - IsInt -> type: 'integer' or items.type (with each: true) * - MinLength -> minLength (for strings) or items.minLength (with each: true) * - MaxLength -> maxLength (for strings) or items.maxLength (with each: true) * - IsUrl -> format: 'uri' or items.format (with each: true) * - IsEmail -> format: 'email' or items.format (with each: true) * - IsPositive -> minimum: 1 or items.minimum (with each: true) */ export declare function inferClassValidatorProperties(target: any, propertyName: string): InferredSchemaProperties;