export function convertNullToNullable ( obj ) { if ( typeof obj . type === 'object' && Array . isArray ( obj . type ) ) { const pos = obj . type . indexOf ( 'null' ) ; if ( pos === - 1 ) return ; obj . type . splice ( pos , 1 ) ; obj . nullable = true ; if ( obj . type . length === 1 ) obj . type = obj . type [ 0 ] ; } else if ( typeof obj . anyOf === 'object' && Array . isArray ( obj . anyOf ) ) { /**
         * E.g
         * {
         *   anyOf: [
         *    { '$ref': '#/definitions/MyType' },
         *    { type: 'null' }
         *   ]
         * },
        */ const pos = obj . anyOf . findIndex ( val => val . type === 'null' ) ; if ( pos === - 1 ) return ; obj . anyOf . splice ( pos , 1 ) ; obj . nullable = true ; if ( obj . anyOf . length === 1 ) { const type = obj . anyOf [ 0 ] ; delete obj . anyOf ; Object . assign ( obj , type ) ; } } }