(schema: z.ZodType)
| 347 | } |
| 348 | |
| 349 | function zodMetadataRegistry(schema: z.ZodType) { |
| 350 | const registry = z.registry<Record<string, unknown>>() |
| 351 | const seen = new WeakSet<object>() |
| 352 | const collect = (value: unknown) => { |
| 353 | if (typeof value !== "object" || value === null) return |
| 354 | if (seen.has(value)) return |
| 355 | seen.add(value) |
| 356 | |
| 357 | if (isZodType(value)) { |
| 358 | const metadata = typeof value.meta === "function" ? value.meta() : undefined |
| 359 | const description = typeof value.description === "string" ? value.description : undefined |
| 360 | const merged = { |
| 361 | ...(metadata && typeof metadata === "object" ? metadata : {}), |
| 362 | ...(description ? { description } : {}), |
| 363 | } |
| 364 | if (Object.keys(merged).length) registry.add(value, merged) |
| 365 | collect(value._zod.def) |
| 366 | return |
| 367 | } |
| 368 | |
| 369 | for (const item of Object.values(value)) collect(item) |
| 370 | } |
| 371 | collect(schema) |
| 372 | return registry |
| 373 | } |
| 374 | |
| 375 | function normalizeZodJsonSchema(value: unknown): unknown { |
| 376 | if (Array.isArray(value)) return value.map((item) => normalizeZodJsonSchema(item)) |
no test coverage detected