UNPKG

json-schema-to-zod

Version:

Converts JSON schema objects or files into Zod schemas

14 lines (13 loc) 495 B
import { parseSchema } from "./parseSchema.js"; export const parseAnyOf = (schema, refs) => { return schema.anyOf.length ? schema.anyOf.length === 1 ? parseSchema(schema.anyOf[0], { ...refs, path: [...refs.path, "anyOf", 0], }) : `z.union([${schema.anyOf .map((schema, i) => parseSchema(schema, { ...refs, path: [...refs.path, "anyOf", i] })) .join(", ")}])` : `z.any()`; };