@@ -134,9 +134,6 @@ function compileOneOfSchema(compiler: Compiler, schema: OpenAPIOneOfSchema) {
134
134
) ,
135
135
) ,
136
136
builders . blockStatement ( [
137
- builders . expressionStatement (
138
- builders . assignmentExpression ( '=' , resultIdentifier , altIdentifier ) ,
139
- ) ,
140
137
...( index > 0
141
138
? [
142
139
builders . ifStatement (
@@ -153,11 +150,25 @@ function compileOneOfSchema(compiler: Compiler, schema: OpenAPIOneOfSchema) {
153
150
) ,
154
151
]
155
152
: [ ] ) ,
153
+ builders . expressionStatement (
154
+ builders . assignmentExpression ( '=' , resultIdentifier , altIdentifier ) ,
155
+ ) ,
156
156
] ) ,
157
157
) ,
158
158
) ;
159
159
} ) ;
160
160
161
+ nodes . push (
162
+ builders . ifStatement (
163
+ builders . binaryExpression (
164
+ '===' ,
165
+ resultIdentifier ,
166
+ builders . identifier ( 'undefined' ) ,
167
+ ) ,
168
+ builders . blockStatement ( [ builders . returnStatement ( error ( 'expected to match one' ) ) ] ) ,
169
+ ) ,
170
+ ) ;
171
+
161
172
nodes . push ( builders . returnStatement ( resultIdentifier ) ) ;
162
173
163
174
return nodes ;
@@ -597,13 +608,14 @@ function compileNumberSchema(
597
608
schema : OpenAPINumberSchema | OpenAPIIntegerSchema ,
598
609
) {
599
610
return compiler . declareValidationFunction ( schema , ( { value, error } ) => {
611
+ const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
612
+ nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
613
+
600
614
const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
601
615
if ( enumCheck ) {
602
- return enumCheck ;
616
+ return [ ... nodes , ... enumCheck ] ;
603
617
}
604
618
605
- const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
606
- nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
607
619
nodes . push (
608
620
builders . ifStatement (
609
621
builders . binaryExpression (
@@ -623,13 +635,14 @@ function compileNumberSchema(
623
635
624
636
function compileStringSchema ( compiler : Compiler , schema : OpenAPIStringSchema ) {
625
637
return compiler . declareValidationFunction ( schema , ( { value, context, path, error } ) => {
638
+ const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
639
+ nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
640
+
626
641
const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
627
642
if ( enumCheck ) {
628
- return enumCheck ;
643
+ return [ ... nodes , ... enumCheck ] ;
629
644
}
630
645
631
- const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
632
- nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
633
646
nodes . push (
634
647
builders . ifStatement (
635
648
builders . binaryExpression (
@@ -752,13 +765,14 @@ function compileStringSchema(compiler: Compiler, schema: OpenAPIStringSchema) {
752
765
753
766
function compileBooleanSchema ( compiler : Compiler , schema : OpenAPIBooleanSchema ) {
754
767
return compiler . declareValidationFunction ( schema , ( { value, error } ) => {
768
+ const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
769
+ nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
770
+
755
771
const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
756
772
if ( enumCheck ) {
757
- return enumCheck ;
773
+ return [ ... nodes , ... enumCheck ] ;
758
774
}
759
775
760
- const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
761
- nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
762
776
nodes . push (
763
777
builders . ifStatement (
764
778
builders . binaryExpression (
0 commit comments