File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed
Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -481,19 +481,25 @@ class Convertor {
481481 } ) ;
482482
483483 if ( hasNullType ) {
484- schemaOf . forEach ( ( obj ) => {
485- if ( obj . type !== "null" ) {
486- obj . nullable = true ;
487- }
488- } ) ;
489- const newOf = schemaOf . filter ( ( obj ) => {
490- if ( obj . type !== "null" ) return obj ;
491- } ) ;
484+ const nullableSchemasFiltered = schemaOf
485+ . filter ( ( schemaContainignNull ) => {
486+ if ( schemaContainignNull . type !== "null" ) {
487+ return schemaContainignNull ;
488+ }
489+ } )
490+ . map ( ( schemasNotContainingNull ) => {
491+ schemasNotContainingNull . nullable = true ;
492+ return schemasNotContainingNull ;
493+ } ) ;
492494
493- if ( isOneOf ) {
494- schema . oneOf = newOf ;
495+ if ( nullableSchemasFiltered . length > 1 ) {
496+ if ( isOneOf ) schema . oneOf = nullableSchemasFiltered ;
497+ else schema . anyOf = nullableSchemasFiltered ;
495498 } else {
496- schema . anyOf = newOf ;
499+ if ( isOneOf ) delete schema . oneOf ;
500+ else delete schema . anyOf ;
501+
502+ Object . assign ( schema , nullableSchemasFiltered [ 0 ] ) ;
497503 }
498504 }
499505 }
You can’t perform that action at this time.
0 commit comments