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 {
119119 this . removeEmptyRequired ( schema )
120120 this . convertNullProperty ( schema )
121121 this . convertDefaultValues ( schema )
122+ this . convertOneOfAnyOfNulls ( schema )
122123 this . removeInvalidFields ( schema )
123124 }
124125
@@ -414,6 +415,35 @@ class Convertor {
414415 schema . anyOf = anyOf
415416 }
416417 }
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+ }
417447}
418448
419449module . exports = Convertor
You can’t perform that action at this time.
0 commit comments