@toolsycc/json-schema-gen
Version:
Generate lightweight JSON Schema objects compatible with OpenAI Function Calling and JSON Mode.
25 lines (24 loc) • 838 B
TypeScript
export type SchemaField = {
type: "string" | "number" | "integer" | "boolean" | "object" | "array";
description?: string;
required?: boolean;
properties?: Record<string, SchemaField>;
items?: SchemaField;
};
export type JsonSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
export type JsonSchema = {
type: JsonSchemaType;
properties?: Record<string, JsonSchema>;
required?: string[];
items?: JsonSchema;
};
export declare function validateSchema(schema: JsonSchema, data: any): {
valid: boolean;
errors: string[];
};
export declare function generateSchema(fields: Record<string, SchemaField>): {
required?: string[] | undefined;
type: string;
properties: Record<string, any>;
};
export declare function generateSchemaFromData(data: any): any;