Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import type { ZodType } from 'zod/v4'; |
| 2 | import { version } from 'zod/v4/core'; |
| 3 | |
| 4 | import { zodV4Backend } from './backend/zod-v4'; |
| 5 | import { ZOD_V4_FLOOR, formatZodVersion, meetsZodV4Floor } from './backend/zod-v4-floor'; |
| 6 | import type { OptionsOf, ParserOverrideOf, RefsOf } from './context'; |
| 7 | import { createConverter } from './convert'; |
| 8 | import type { JsonSchema, JsonSchemaObject } from './types'; |
| 9 | |
| 10 | export type { Serializable, JsonSchema, JsonSchemaObject } from './types'; |
| 11 | export { InvalidPatternError, type InvalidPatternReason } from './utils/compile-pattern'; |
| 12 | |
| 13 | if (!meetsZodV4Floor(version)) { |
| 14 | throw new Error( |
| 15 | `@composio/json-schema-to-zod/v4 requires zod >= ${formatZodVersion(ZOD_V4_FLOOR)}; found ${formatZodVersion(version)}` |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | export type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => ZodType; |
| 20 | export type ParserOverride = ParserOverrideOf<ZodType>; |
| 21 | export type JsonSchemaToZodOptions = OptionsOf<ZodType> & { |
| 22 | /** Leave out the forwarded `format`, `contentEncoding`, `contentMediaType`, and integer annotations. */ |
| 23 | withoutAnnotations?: boolean; |
| 24 | }; |
| 25 | export type Refs = RefsOf<ZodType>; |
| 26 | |
| 27 | /** A raw shape over zod v4 schemas, for APIs that take a shape rather than an object schema. */ |
| 28 | export type SimpleZodRawShape = Record<string, ZodType>; |
| 29 | |
| 30 | const converter = createConverter(zodV4Backend); |
| 31 | |
| 32 | export const jsonSchemaToZod = ( |
| 33 | schema: JsonSchema, |
| 34 | options: JsonSchemaToZodOptions = {} |
| 35 | ): ZodType => converter.jsonSchemaToZod(schema, options); |
| 36 | |
| 37 | export const jsonSchemaToZodShape = ( |
| 38 | schema: JsonSchema, |
| 39 | options: JsonSchemaToZodOptions = {} |
| 40 | ): SimpleZodRawShape => converter.jsonSchemaToZodShape(schema, options); |