@@ -25,6 +25,10 @@ function zodToJsonSchema(schema: ZodType, options: { name: string }): Record<str
2525 } ) ;
2626}
2727
28+ function nativeToJsonSchema ( schema : ZodTypeV4 ) : Record < string , unknown > {
29+ return toJSONSchema ( schema , { target : 'draft-7' } ) as Record < string , unknown > ;
30+ }
31+
2832function isZodV4 ( zodObject : ZodType | ZodTypeV4 ) : zodObject is ZodTypeV4 {
2933 return '_zod' in zodObject ;
3034}
@@ -90,7 +94,7 @@ export function zodResponseFormat<ZodInput extends ZodType | ZodTypeV4>(
9094 strict : true ,
9195 schema :
9296 isZodV4 ( zodObject ) ?
93- ( toStrictJsonSchema ( toJSONSchema ( zodObject ) as JSONSchema ) as Record < string , unknown > )
97+ ( toStrictJsonSchema ( nativeToJsonSchema ( zodObject ) ) as Record < string , unknown > )
9498 : zodToJsonSchema ( zodObject , { name } ) ,
9599 } ,
96100 } ,
@@ -121,7 +125,7 @@ export function zodTextFormat<ZodInput extends ZodType | ZodTypeV4>(
121125 strict : true ,
122126 schema :
123127 isZodV4 ( zodObject ) ?
124- ( toStrictJsonSchema ( toJSONSchema ( zodObject ) as JSONSchema ) as Record < string , unknown > )
128+ ( toStrictJsonSchema ( nativeToJsonSchema ( zodObject ) ) as Record < string , unknown > )
125129 : zodToJsonSchema ( zodObject , { name } ) ,
126130 } ,
127131 ( content ) => zodObject . parse ( JSON . parse ( content ) ) ,
@@ -166,7 +170,7 @@ export function zodFunction<Parameters extends ZodType | ZodTypeV4>(options: {
166170 name : options . name ,
167171 parameters :
168172 isZodV4 ( options . parameters ) ?
169- toJSONSchema ( options . parameters )
173+ nativeToJsonSchema ( options . parameters )
170174 : zodToJsonSchema ( options . parameters , { name : options . name } ) ,
171175 strict : true ,
172176 ...( options . description ? { description : options . description } : undefined ) ,
0 commit comments