@@ -69,15 +69,20 @@ const resolveZodType = (schemaTypeValue: SchemaObject['type']) => {
69
69
let constsUniqueCounter : Record < string , number > = { } ;
70
70
71
71
// https://github.com/colinhacks/zod#coercion-for-primitives
72
- const COERCEABLE_TYPES = [ 'string' , 'number' , 'boolean' , 'bigint' , 'date' ] ;
72
+ const COERCIBLE_TYPES = [ 'string' , 'number' , 'boolean' , 'bigint' , 'date' ] ;
73
+
74
+ export type ZodValidationSchemaDefinition = {
75
+ functions : [ string , any ] [ ] ;
76
+ consts : string [ ] ;
77
+ } ;
73
78
74
79
export const generateZodValidationSchemaDefinition = (
75
80
schema : SchemaObject | undefined ,
76
81
context : ContextSpecs ,
77
82
_required : boolean | undefined ,
78
83
name : string ,
79
84
strict : boolean ,
80
- ) : { functions : [ string , any ] [ ] ; consts : string [ ] } => {
85
+ ) : ZodValidationSchemaDefinition => {
81
86
if ( ! schema ) return { functions : [ ] , consts : [ ] } ;
82
87
83
88
const consts : string [ ] = [ ] ;
@@ -223,15 +228,15 @@ export const generateZodValidationSchemaDefinition = (
223
228
if ( schema . additionalProperties ) {
224
229
functions . push ( [
225
230
'additionalProperties' ,
226
- isBoolean ( schema . additionalProperties )
227
- ? schema . additionalProperties
228
- : generateZodValidationSchemaDefinition (
229
- schema . additionalProperties as SchemaObject ,
230
- context ,
231
- true ,
232
- name ,
233
- strict ,
234
- ) ,
231
+ generateZodValidationSchemaDefinition (
232
+ isBoolean ( schema . additionalProperties )
233
+ ? { }
234
+ : ( schema . additionalProperties as SchemaObject ) ,
235
+ context ,
236
+ true ,
237
+ name ,
238
+ strict ,
239
+ ) ,
235
240
] ) ;
236
241
237
242
break ;
@@ -291,14 +296,9 @@ export const generateZodValidationSchemaDefinition = (
291
296
return { functions, consts : uniq ( consts ) } ;
292
297
} ;
293
298
294
- export type ZodValidationSchemaDefinitionInput = {
295
- functions : [ string , any ] [ ] ;
296
- consts : string [ ] ;
297
- } ;
298
-
299
299
export const parseZodValidationSchemaDefinition = (
300
- input : ZodValidationSchemaDefinitionInput ,
301
- contex : ContextSpecs ,
300
+ input : ZodValidationSchemaDefinition ,
301
+ context : ContextSpecs ,
302
302
coerceTypes : boolean | ZodCoerceType [ ] = false ,
303
303
preprocessResponse ?: GeneratorMutator ,
304
304
) : { zod : string ; consts : string } => {
@@ -359,10 +359,10 @@ export const parseZodValidationSchemaDefinition = (
359
359
return `zod.object({
360
360
${ Object . entries ( args )
361
361
. map ( ( [ key , schema ] ) => {
362
- const value = ( schema as ZodValidationSchemaDefinitionInput ) . functions
362
+ const value = ( schema as ZodValidationSchemaDefinition ) . functions
363
363
. map ( parseProperty )
364
364
. join ( '' ) ;
365
- consts += ( schema as ZodValidationSchemaDefinitionInput ) . consts . join ( '\n' ) ;
365
+ consts += ( schema as ZodValidationSchemaDefinition ) . consts . join ( '\n' ) ;
366
366
return ` "${ key } ": ${ value . startsWith ( '.' ) ? 'zod' : '' } ${ value } ` ;
367
367
} )
368
368
. join ( ',\n' ) }
@@ -386,11 +386,11 @@ ${Object.entries(args)
386
386
coerceTypes &&
387
387
( Array . isArray ( coerceTypes )
388
388
? coerceTypes . includes ( fn as ZodCoerceType )
389
- : COERCEABLE_TYPES . includes ( fn ) ) ;
389
+ : COERCIBLE_TYPES . includes ( fn ) ) ;
390
390
391
391
if (
392
392
( fn !== 'date' && shouldCoerceType ) ||
393
- ( fn === 'date' && shouldCoerceType && contex . output . override . useDates )
393
+ ( fn === 'date' && shouldCoerceType && context . output . override . useDates )
394
394
) {
395
395
return `.coerce.${ fn } (${ args } )` ;
396
396
}
@@ -460,7 +460,7 @@ const parseBodyAndResponse = ({
460
460
name : string ;
461
461
strict : boolean ;
462
462
} ) : {
463
- input : ZodValidationSchemaDefinitionInput ;
463
+ input : ZodValidationSchemaDefinition ;
464
464
isArray : boolean ;
465
465
} => {
466
466
if ( ! data ) {
@@ -530,9 +530,9 @@ const parseParameters = ({
530
530
response : boolean ;
531
531
} ;
532
532
} ) : {
533
- headers : ZodValidationSchemaDefinitionInput ;
534
- queryParams : ZodValidationSchemaDefinitionInput ;
535
- params : ZodValidationSchemaDefinitionInput ;
533
+ headers : ZodValidationSchemaDefinition ;
534
+ queryParams : ZodValidationSchemaDefinition ;
535
+ params : ZodValidationSchemaDefinition ;
536
536
} => {
537
537
if ( ! data ) {
538
538
return {
@@ -608,7 +608,7 @@ const parseParameters = ({
608
608
> ,
609
609
) ;
610
610
611
- const headers : ZodValidationSchemaDefinitionInput = {
611
+ const headers : ZodValidationSchemaDefinition = {
612
612
functions : [ ] ,
613
613
consts : [ ] ,
614
614
} ;
@@ -621,7 +621,7 @@ const parseParameters = ({
621
621
}
622
622
}
623
623
624
- const queryParams : ZodValidationSchemaDefinitionInput = {
624
+ const queryParams : ZodValidationSchemaDefinition = {
625
625
functions : [ ] ,
626
626
consts : [ ] ,
627
627
} ;
@@ -634,7 +634,7 @@ const parseParameters = ({
634
634
}
635
635
}
636
636
637
- const params : ZodValidationSchemaDefinitionInput = {
637
+ const params : ZodValidationSchemaDefinition = {
638
638
functions : [ ] ,
639
639
consts : [ ] ,
640
640
} ;
0 commit comments