File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ class Convertor {
119
119
this . removeEmptyRequired ( schema )
120
120
this . convertNullProperty ( schema )
121
121
this . convertDefaultValues ( schema )
122
+ this . convertOneOfAnyOfNulls ( schema )
122
123
this . removeInvalidFields ( schema )
123
124
}
124
125
@@ -414,6 +415,35 @@ class Convertor {
414
415
schema . anyOf = anyOf
415
416
}
416
417
}
418
+
419
+ convertOneOfAnyOfNulls ( schema ) {
420
+ if ( schema . oneOf || schema . anyOf ) {
421
+ const isOneOf = Boolean ( schema . oneOf )
422
+ const schemaOf = schema . oneOf || schema . anyOf
423
+ const hasNullType = schemaOf . some ( obj => {
424
+ if ( obj . type === 'null' )
425
+ return true
426
+ } )
427
+
428
+ if ( hasNullType ) {
429
+ schemaOf . forEach ( obj => {
430
+ if ( obj . type !== 'null' ) {
431
+ obj . nullable = true
432
+ }
433
+ } )
434
+ const newOf = schemaOf . filter ( obj => {
435
+ if ( obj . type !== 'null' )
436
+ return obj
437
+ } )
438
+
439
+ if ( isOneOf ) {
440
+ schema . oneOf = newOf
441
+ } else {
442
+ schema . anyOf = newOf
443
+ }
444
+ }
445
+ }
446
+ }
417
447
}
418
448
419
449
module . exports = Convertor
You can’t perform that action at this time.
0 commit comments