diff --git a/src/utils/schema.ts b/src/utils/schema.ts new file mode 100644 index 0000000..516d1d1 --- /dev/null +++ b/src/utils/schema.ts @@ -0,0 +1,31 @@ +import { z } from 'zod'; + +export function createResponseSchema(config: { + type: 'object'; + properties: Record; + required: string[]; +}) { + const properties: Record = {}; + + for (const [key, prop] of Object.entries(config.properties)) { + if (prop.type === 'STRING') { + properties[key] = z.string().describe(prop.description); + } else if (prop.type === 'BOOLEAN') { + properties[key] = z.boolean().describe(prop.description); + } else if (prop.type === 'ARRAY') { + const itemSchema = prop.items.type === 'STRING' ? z.string() : z.object({}); + properties[key] = z.array(itemSchema) + .describe(prop.description) + .max(prop.maxItems || Infinity) + .min(prop.minItems || 0); + } + } + + return z.object(properties); +}