import { z } from 'zod'; export function toInputJsonSchema(schema: z.ZodType): Record { const jsonSchema = z.toJSONSchema(schema, { target: 'draft-7', io: 'input', }); closeObjectNodes(jsonSchema); return jsonSchema; } function closeObjectNodes(value: unknown): void { if (Array.isArray(value)) { for (const item of value) closeObjectNodes(item); return; } if (typeof value !== 'object' || value === null) return; const node = value as Record; if (node['type'] === 'object' && node['additionalProperties'] === undefined) { node['additionalProperties'] = false; } for (const child of Object.values(node)) { closeObjectNodes(child); } }