@firefliesai/schema-forge
Version:
Transform TypeScript classes into JSON Schema definitions with automatic support for OpenAI, Anthropic, and Google Gemini function calling (tool) formats
52 lines (51 loc) • 1.72 kB
TypeScript
/**
* Helper functions for schema-forge
*/
/**
* Clones metadata using JSON serialization/deserialization
*/
export declare function cloneMetadata(metadata: any): any;
/**
* Prepares a JSON Schema object for OpenAI structured output compatibility.
*
* This function:
* - Adds additionalProperties:false to enforce strict schema validation
* - Makes all properties required (adds them to the required array)
* - Removes JSON Schema features not supported by OpenAI
* - Optionally converts optional properties to use ["type", "null"] format
*
* @public
* @param schema The JSON Schema object to enhance
* @param handleOptionals Whether to convert optional properties to ["type", "null"] format
* @returns Enhanced JSON Schema object ready for OpenAI structured output
*
* @example
* // Enhance a JSON Schema for OpenAI structured output
* const schema = {
* type: 'object',
* properties: {
* name: { type: 'string' },
* age: { type: 'number' }
* },
* required: ['name']
* };
* const enhancedSchema = prepareForOpenAIStructuredOutput(schema, true);
* // age will be transformed to { type: ["number", "null"] }
*/
export declare function prepareForOpenAIStructuredOutput(obj: any, handleOptionals?: boolean): any;
/**
* Type inference helper
*/
export declare function inferType<T>(_target: new (...args: any[]) => any): T;
/**
* Checks if a type is a custom class
*/
export declare function isCustomClass(type: any): boolean;
/**
* Extracts values from an enum type
*/
export declare function extractEnumValues(enumType: any): any[];
/**
* Gets the corresponding JSON Schema type for a TypeScript type
*/
export declare function getJsonSchemaType(type: any): string;