@@ -350,6 +350,12 @@ describe("utils", function() {
350
350
expect ( result ) . toEqual ( expectedError )
351
351
}
352
352
353
+ const assertValidateOas3Param = ( param , expectedError ) => {
354
+ // for cases where you _only_ want to try OAS3
355
+ result = validateParam ( fromJS ( param ) , false , true )
356
+ expect ( result ) . toEqual ( expectedError )
357
+ }
358
+
353
359
it ( "should check the isOAS3 flag when validating parameters" , function ( ) {
354
360
// This should "skip" validation because there is no `schema` property
355
361
// and we are telling `validateParam` this is an OAS3 spec
@@ -361,6 +367,92 @@ describe("utils", function() {
361
367
expect ( result ) . toEqual ( [ ] )
362
368
} )
363
369
370
+ it ( "validates required OAS3 objects" , function ( ) {
371
+ // valid object
372
+ param = {
373
+ required : true ,
374
+ schema : {
375
+ type : "object"
376
+ } ,
377
+ value : {
378
+ abc : 123
379
+ }
380
+ }
381
+ assertValidateOas3Param ( param , [ ] )
382
+
383
+ // valid object-as-string
384
+ param = {
385
+ required : true ,
386
+ schema : {
387
+ type : "object"
388
+ } ,
389
+ value : JSON . stringify ( {
390
+ abc : 123
391
+ } )
392
+ }
393
+ assertValidateOas3Param ( param , [ ] )
394
+
395
+ // invalid object-as-string
396
+ param = {
397
+ required : true ,
398
+ schema : {
399
+ type : "object"
400
+ } ,
401
+ value : "{{}"
402
+ }
403
+ assertValidateOas3Param ( param , [ "Parameter string value must be valid JSON" ] )
404
+
405
+ // missing when required
406
+ param = {
407
+ required : true ,
408
+ schema : {
409
+ type : "object"
410
+ } ,
411
+ }
412
+ assertValidateOas3Param ( param , [ "Required field is not provided" ] )
413
+ } )
414
+
415
+ it ( "validates optional OAS3 objects" , function ( ) {
416
+ // valid object
417
+ param = {
418
+ schema : {
419
+ type : "object"
420
+ } ,
421
+ value : {
422
+ abc : 123
423
+ }
424
+ }
425
+ assertValidateOas3Param ( param , [ ] )
426
+
427
+ // valid object-as-string
428
+ param = {
429
+ schema : {
430
+ type : "object"
431
+ } ,
432
+ value : JSON . stringify ( {
433
+ abc : 123
434
+ } )
435
+ }
436
+ assertValidateOas3Param ( param , [ ] )
437
+
438
+ // invalid object-as-string
439
+ param = {
440
+ schema : {
441
+ type : "object"
442
+ } ,
443
+ value : "{{}"
444
+ }
445
+ assertValidateOas3Param ( param , [ "Parameter string value must be valid JSON" ] )
446
+
447
+ // missing when not required
448
+ param = {
449
+ schema : {
450
+ type : "object"
451
+ } ,
452
+ }
453
+ assertValidateOas3Param ( param , [ ] )
454
+ } )
455
+
364
456
it ( "validates required strings" , function ( ) {
365
457
// invalid string
366
458
param = {
@@ -962,7 +1054,7 @@ describe("utils", function() {
962
1054
expect ( result ) . toEqual ( Map ( [ [ "minimum" , "b" ] ] ) )
963
1055
} )
964
1056
} )
965
-
1057
+
966
1058
describe ( "deeplyStripKey" , function ( ) {
967
1059
it ( "should filter out a specified key" , function ( ) {
968
1060
const input = {
@@ -1065,8 +1157,7 @@ describe("utils", function() {
1065
1157
} )
1066
1158
1067
1159
it ( "should sanitize a `data:` url" , function ( ) {
1068
- const res = sanitizeUrl ( `data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGV
1069
- sbG8iKTs8L3NjcmlwdD4=` )
1160
+ const res = sanitizeUrl ( `data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGVsbG8iKTs8L3NjcmlwdD4=` )
1070
1161
1071
1162
expect ( res ) . toEqual ( "about:blank" )
1072
1163
} )
0 commit comments