mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-09 11:57:28 -08:00
16 lines
383 B
TypeScript
16 lines
383 B
TypeScript
|
import type { z } from 'zod';
|
||
|
|
||
|
import { parseSchema } from './parsers/parse-schema';
|
||
|
import type { JsonSchemaToZodOptions, JsonSchema } from './types';
|
||
|
|
||
|
export const jsonSchemaToZod = <T extends z.ZodTypeAny = z.ZodTypeAny>(
|
||
|
schema: JsonSchema,
|
||
|
options: JsonSchemaToZodOptions = {},
|
||
|
): T => {
|
||
|
return parseSchema(schema, {
|
||
|
path: [],
|
||
|
seen: new Map(),
|
||
|
...options,
|
||
|
}) as T;
|
||
|
};
|