@@ -213,6 +213,23 @@ function compileObjectSchema(compiler: Compiler, schema: OpenAPIObjectSchema) {
213
213
214
214
nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
215
215
216
+ nodes . push (
217
+ builders . ifStatement (
218
+ builders . logicalExpression ( '||' ,
219
+ builders . binaryExpression (
220
+ '!==' ,
221
+ builders . unaryExpression ( 'typeof' , value ) ,
222
+ builders . literal ( 'object' ) ,
223
+ ) ,
224
+ builders . binaryExpression (
225
+ '===' ,
226
+ value ,
227
+ builders . identifier ( 'null' ) ,
228
+ ) ) ,
229
+ builders . blockStatement ( [ builders . returnStatement ( error ( 'Expected an object' ) ) ] ) ,
230
+ ) ,
231
+ ) ;
232
+
216
233
// Define a variable to be all the keys in `value`
217
234
const keysIdentifier = builders . identifier ( 'keys' ) ;
218
235
@@ -318,20 +335,18 @@ function compileObjectSchema(compiler: Compiler, schema: OpenAPIObjectSchema) {
318
335
) ,
319
336
] ;
320
337
321
- if ( schema . additionalProperties ) {
322
- // Remove the key from the keys set
323
- check . push (
324
- builders . expressionStatement (
325
- builders . callExpression (
326
- builders . memberExpression (
327
- keysIdentifier ,
328
- builders . identifier ( 'delete' ) ,
329
- ) ,
330
- [ propNameLiteral ] ,
338
+ // Remove the key from the keys set
339
+ check . push (
340
+ builders . expressionStatement (
341
+ builders . callExpression (
342
+ builders . memberExpression (
343
+ keysIdentifier ,
344
+ builders . identifier ( 'delete' ) ,
331
345
) ,
346
+ [ propNameLiteral ] ,
332
347
) ,
333
- ) ;
334
- }
348
+ ) ,
349
+ ) ;
335
350
336
351
nodes . push (
337
352
builders . ifStatement (
@@ -461,13 +476,10 @@ function compileNumberSchema(
461
476
nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
462
477
nodes . push (
463
478
builders . ifStatement (
464
- builders . unaryExpression (
465
- '!' ,
466
- builders . binaryExpression (
467
- '===' ,
468
- builders . unaryExpression ( 'typeof' , value ) ,
469
- builders . literal ( 'number' ) ,
470
- ) ,
479
+ builders . binaryExpression (
480
+ '!==' ,
481
+ builders . unaryExpression ( 'typeof' , value ) ,
482
+ builders . literal ( 'number' ) ,
471
483
) ,
472
484
builders . blockStatement ( [ builders . returnStatement ( error ( 'Expected a number' ) ) ] ) ,
473
485
) ,
@@ -490,13 +502,10 @@ function compileStringSchema(compiler: Compiler, schema: OpenAPIStringSchema) {
490
502
nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
491
503
nodes . push (
492
504
builders . ifStatement (
493
- builders . unaryExpression (
494
- '!' ,
495
- builders . binaryExpression (
496
- '===' ,
497
- builders . unaryExpression ( 'typeof' , value ) ,
498
- builders . literal ( 'string' ) ,
499
- ) ,
505
+ builders . binaryExpression (
506
+ '!==' ,
507
+ builders . unaryExpression ( 'typeof' , value ) ,
508
+ builders . literal ( 'string' ) ,
500
509
) ,
501
510
builders . blockStatement ( [ builders . returnStatement ( error ( 'Expected a string' ) ) ] ) ,
502
511
) ,
@@ -584,13 +593,10 @@ function compileBooleanSchema(compiler: Compiler, schema: OpenAPIBooleanSchema)
584
593
nodes . push ( ...compileNullableCheck ( compiler , schema , value ) ) ;
585
594
nodes . push (
586
595
builders . ifStatement (
587
- builders . unaryExpression (
588
- '!' ,
589
- builders . binaryExpression (
590
- '===' ,
591
- builders . unaryExpression ( 'typeof' , value ) ,
592
- builders . literal ( 'boolean' ) ,
593
- ) ,
596
+ builders . binaryExpression (
597
+ '!==' ,
598
+ builders . unaryExpression ( 'typeof' , value ) ,
599
+ builders . literal ( 'boolean' ) ,
594
600
) ,
595
601
builders . blockStatement ( [ builders . returnStatement ( error ( 'Expected a boolean' ) ) ] ) ,
596
602
) ,
0 commit comments