File tree 2 files changed +43
-1
lines changed
2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ export function addDefaultValueToSchema(
14
14
schema : Record < string , any >
15
15
) : Record < string , any > {
16
16
return Object . entries ( schema ) . reduce ( ( acc , [ key , value ] ) => {
17
- if ( value !== null && typeof value == "object" ) {
17
+ if (
18
+ value !== null &&
19
+ typeof value == "object" &&
20
+ Array . isArray ( value ) === false
21
+ ) {
18
22
acc [ key ] = addDefaultValueToSchema ( value ) ;
19
23
} else {
20
24
acc [ key ] = value ;
Original file line number Diff line number Diff line change @@ -445,4 +445,42 @@ describe("#addDefaultValueToSchema", () => {
445
445
additionalProperties : true ,
446
446
} ) ;
447
447
} ) ;
448
+
449
+ it ( "should allow both objects and lists" , ( ) => {
450
+ const res = addDefaultValueToSchema ( {
451
+ properties : {
452
+ success : {
453
+ type : "object" ,
454
+ required : [ "ok" ] ,
455
+ properties : {
456
+ ok : {
457
+ type : "boolean" ,
458
+ } ,
459
+ } ,
460
+ } ,
461
+ message : {
462
+ type : "string" ,
463
+ } ,
464
+ } ,
465
+ } ) ;
466
+
467
+ expect ( res ) . toEqual ( {
468
+ properties : {
469
+ success : {
470
+ type : "object" ,
471
+ required : [ "ok" ] ,
472
+ additionalProperties : false ,
473
+ properties : {
474
+ ok : {
475
+ type : "boolean" ,
476
+ } ,
477
+ } ,
478
+ } ,
479
+ message : {
480
+ type : "string" ,
481
+ } ,
482
+ } ,
483
+ additionalProperties : false ,
484
+ } ) ;
485
+ } ) ;
448
486
} ) ;
You can’t perform that action at this time.
0 commit comments