@@ -134,9 +134,6 @@ function compileOneOfSchema(compiler: Compiler, schema: OpenAPIOneOfSchema) {
134134 ) ,
135135 ) ,
136136 builders . blockStatement ( [
137- builders . expressionStatement (
138- builders . assignmentExpression ( '=' , resultIdentifier , altIdentifier ) ,
139- ) ,
140137 ...( index > 0
141138 ? [
142139 builders . ifStatement (
@@ -153,11 +150,25 @@ function compileOneOfSchema(compiler: Compiler, schema: OpenAPIOneOfSchema) {
153150 ) ,
154151 ]
155152 : [ ] ) ,
153+ builders . expressionStatement (
154+ builders . assignmentExpression ( '=' , resultIdentifier , altIdentifier ) ,
155+ ) ,
156156 ] ) ,
157157 ) ,
158158 ) ;
159159 } ) ;
160160
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+
161172 nodes . push ( builders . returnStatement ( resultIdentifier ) ) ;
162173
163174 return nodes ;
@@ -597,13 +608,14 @@ function compileNumberSchema(
597608 schema : OpenAPINumberSchema | OpenAPIIntegerSchema ,
598609) {
599610 return compiler . declareValidationFunction ( schema , ( { value, error } ) => {
611+ const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
612+ nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
613+
600614 const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
601615 if ( enumCheck ) {
602- return enumCheck ;
616+ return [ ... nodes , ... enumCheck ] ;
603617 }
604618
605- const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
606- nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
607619 nodes . push (
608620 builders . ifStatement (
609621 builders . binaryExpression (
@@ -623,13 +635,14 @@ function compileNumberSchema(
623635
624636function compileStringSchema ( compiler : Compiler , schema : OpenAPIStringSchema ) {
625637 return compiler . declareValidationFunction ( schema , ( { value, context, path, error } ) => {
638+ const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
639+ nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
640+
626641 const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
627642 if ( enumCheck ) {
628- return enumCheck ;
643+ return [ ... nodes , ... enumCheck ] ;
629644 }
630645
631- const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
632- nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
633646 nodes . push (
634647 builders . ifStatement (
635648 builders . binaryExpression (
@@ -752,13 +765,14 @@ function compileStringSchema(compiler: Compiler, schema: OpenAPIStringSchema) {
752765
753766function compileBooleanSchema ( compiler : Compiler , schema : OpenAPIBooleanSchema ) {
754767 return compiler . declareValidationFunction ( schema , ( { value, error } ) => {
768+ const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
769+ nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
770+
755771 const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
756772 if ( enumCheck ) {
757- return enumCheck ;
773+ return [ ... nodes , ... enumCheck ] ;
758774 }
759775
760- const nodes : namedTypes . BlockStatement [ 'body' ] = [ ] ;
761- nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
762776 nodes . push (
763777 builders . ifStatement (
764778 builders . binaryExpression (
0 commit comments