@@ -40,13 +40,13 @@ const zIdentifier = compiler.identifier({ text: 'z' });
40
40
const nameTransformer = ( name : string ) => `z-${ name } ` ;
41
41
42
42
const arrayTypeToZodSchema = ( {
43
- config,
44
43
context,
44
+ plugin,
45
45
result,
46
46
schema,
47
47
} : {
48
- config : Omit < Config , 'name' > ;
49
48
context : IR . Context ;
49
+ plugin : Config ;
50
50
result : Result ;
51
51
schema : SchemaWithType < 'array' > ;
52
52
} ) : ts . CallExpression => {
@@ -75,8 +75,8 @@ const arrayTypeToZodSchema = ({
75
75
// at least one item is guaranteed
76
76
const itemExpressions = schema . items ! . map ( ( item ) =>
77
77
schemaToZodSchema ( {
78
- config,
79
78
context,
79
+ plugin,
80
80
result,
81
81
schema : item ,
82
82
} ) ,
@@ -334,13 +334,13 @@ const numberTypeToZodSchema = ({
334
334
} ;
335
335
336
336
const objectTypeToZodSchema = ( {
337
- config,
338
337
context,
338
+ plugin,
339
339
result,
340
340
schema,
341
341
} : {
342
- config : Omit < Config , 'name' > ;
343
342
context : IR . Context ;
343
+ plugin : Config ;
344
344
result : Result ;
345
345
schema : SchemaWithType < 'object' > ;
346
346
} ) => {
@@ -358,9 +358,9 @@ const objectTypeToZodSchema = ({
358
358
const isRequired = required . includes ( name ) ;
359
359
360
360
const propertyExpression = schemaToZodSchema ( {
361
- config,
362
361
context,
363
362
optional : ! isRequired ,
363
+ plugin,
364
364
result,
365
365
schema : property ,
366
366
} ) ;
@@ -438,11 +438,11 @@ const objectTypeToZodSchema = ({
438
438
} ;
439
439
440
440
const stringTypeToZodSchema = ( {
441
- config ,
441
+ plugin ,
442
442
schema,
443
443
} : {
444
- config : Omit < Config , 'name' > ;
445
444
context : IR . Context ;
445
+ plugin : Config ;
446
446
schema : SchemaWithType < 'string' > ;
447
447
} ) => {
448
448
if ( typeof schema . const === 'string' ) {
@@ -472,8 +472,8 @@ const stringTypeToZodSchema = ({
472
472
name : compiler . identifier ( { text : 'datetime' } ) ,
473
473
} ) ,
474
474
parameters : [
475
- config . dateTimeOptions
476
- ? JSON . stringify ( config . dateTimeOptions )
475
+ plugin . dateTimeOptions
476
+ ? JSON . stringify ( plugin . dateTimeOptions )
477
477
: undefined ,
478
478
] ,
479
479
} ) ;
@@ -655,21 +655,21 @@ const voidTypeToZodSchema = ({
655
655
} ;
656
656
657
657
const schemaTypeToZodSchema = ( {
658
- config,
659
658
context,
659
+ plugin,
660
660
result,
661
661
schema,
662
662
} : {
663
- config : Omit < Config , 'name' > ;
664
663
context : IR . Context ;
664
+ plugin : Config ;
665
665
result : Result ;
666
666
schema : IR . SchemaObject ;
667
667
} ) : ts . Expression => {
668
668
switch ( schema . type as Required < IR . SchemaObject > [ 'type' ] ) {
669
669
case 'array' :
670
670
return arrayTypeToZodSchema ( {
671
- config,
672
671
context,
672
+ plugin,
673
673
result,
674
674
schema : schema as SchemaWithType < 'array' > ,
675
675
} ) ;
@@ -701,15 +701,15 @@ const schemaTypeToZodSchema = ({
701
701
} ) ;
702
702
case 'object' :
703
703
return objectTypeToZodSchema ( {
704
- config,
705
704
context,
705
+ plugin,
706
706
result,
707
707
schema : schema as SchemaWithType < 'object' > ,
708
708
} ) ;
709
709
case 'string' :
710
710
return stringTypeToZodSchema ( {
711
- config,
712
711
context,
712
+ plugin,
713
713
schema : schema as SchemaWithType < 'string' > ,
714
714
} ) ;
715
715
case 'tuple' :
@@ -736,14 +736,14 @@ const schemaTypeToZodSchema = ({
736
736
} ;
737
737
738
738
const operationToZodSchema = ( {
739
- config,
740
739
context,
741
740
operation,
741
+ plugin,
742
742
result,
743
743
} : {
744
- config : Omit < Config , 'name' > ;
745
744
context : IR . Context ;
746
745
operation : IR . OperationObject ;
746
+ plugin : Config ;
747
747
result : Result ;
748
748
} ) => {
749
749
if ( operation . responses ) {
@@ -756,8 +756,8 @@ const operationToZodSchema = ({
756
756
id : operation . id ,
757
757
type : 'response' ,
758
758
} ) ,
759
- config,
760
759
context,
760
+ plugin,
761
761
result,
762
762
schema : response ,
763
763
} ) ;
@@ -767,24 +767,24 @@ const operationToZodSchema = ({
767
767
768
768
const schemaToZodSchema = ( {
769
769
$ref,
770
- config,
771
770
context,
772
771
optional,
772
+ plugin,
773
773
result,
774
774
schema,
775
775
} : {
776
776
/**
777
777
* When $ref is supplied, a node will be emitted to the file.
778
778
*/
779
779
$ref ?: string ;
780
- config : Omit < Config , 'name' > ;
781
780
context : IR . Context ;
782
781
/**
783
782
* Accept `optional` to handle optional object properties. We can't handle
784
783
* this inside the object function because `.optional()` must come before
785
784
* `.default()` which is handled in this function.
786
785
*/
787
786
optional ?: boolean ;
787
+ plugin : Config ;
788
788
result : Result ;
789
789
schema : IR . SchemaObject ;
790
790
} ) : ts . Expression => {
@@ -821,8 +821,8 @@ const schemaToZodSchema = ({
821
821
if ( ! identifierRef . name ) {
822
822
const ref = context . resolveIrRef < IR . SchemaObject > ( schema . $ref ) ;
823
823
expression = schemaToZodSchema ( {
824
- config,
825
824
context,
825
+ plugin,
826
826
result,
827
827
schema : ref ,
828
828
} ) ;
@@ -860,8 +860,8 @@ const schemaToZodSchema = ({
860
860
}
861
861
} else if ( schema . type ) {
862
862
expression = schemaTypeToZodSchema ( {
863
- config,
864
863
context,
864
+ plugin,
865
865
result,
866
866
schema,
867
867
} ) ;
@@ -871,8 +871,8 @@ const schemaToZodSchema = ({
871
871
if ( schema . items ) {
872
872
const itemTypes = schema . items . map ( ( item ) =>
873
873
schemaToZodSchema ( {
874
- config,
875
874
context,
875
+ plugin,
876
876
result,
877
877
schema : item ,
878
878
} ) ,
@@ -921,17 +921,17 @@ const schemaToZodSchema = ({
921
921
}
922
922
} else {
923
923
expression = schemaToZodSchema ( {
924
- config,
925
924
context,
925
+ plugin,
926
926
result,
927
927
schema,
928
928
} ) ;
929
929
}
930
930
} else {
931
931
// catch-all fallback for failed schemas
932
932
expression = schemaTypeToZodSchema ( {
933
- config,
934
933
context,
934
+ plugin,
935
935
result,
936
936
schema : {
937
937
type : 'unknown' ,
@@ -1010,20 +1010,16 @@ export const handler: Plugin.Handler<Config> = ({ context, plugin }) => {
1010
1010
name : 'z' ,
1011
1011
} ) ;
1012
1012
1013
- const config : Omit < Config , 'name' > = {
1014
- dateTimeOptions : plugin . dateTimeOptions ,
1015
- } ;
1016
-
1017
1013
context . subscribe ( 'operation' , ( { operation } ) => {
1018
1014
const result : Result = {
1019
1015
circularReferenceTracker : new Set ( ) ,
1020
1016
hasCircularReference : false ,
1021
1017
} ;
1022
1018
1023
1019
operationToZodSchema ( {
1024
- config,
1025
1020
context,
1026
1021
operation,
1022
+ plugin,
1027
1023
result,
1028
1024
} ) ;
1029
1025
} ) ;
@@ -1036,8 +1032,8 @@ export const handler: Plugin.Handler<Config> = ({ context, plugin }) => {
1036
1032
1037
1033
schemaToZodSchema ( {
1038
1034
$ref,
1039
- config,
1040
1035
context,
1036
+ plugin,
1041
1037
result,
1042
1038
schema,
1043
1039
} ) ;
0 commit comments