@@ -192,7 +192,10 @@ function parseType(context) {
192192 ensureTypesAreUnique ,
193193
194194 // FIXME support >1 type
195- R . when ( e => e . length > 1 , createWarning ( namespace , `'${ name } ' 'type' more than one type is current unsupported` ) ) ) ;
195+ R . unless (
196+ e => e . length === 0 || e . length === 1 || ( e . length === 2 && e . contains ( 'null' ) ) ,
197+ createWarning ( namespace , `'${ name } ' 'type' more than one type is current unsupported` )
198+ ) ) ;
196199
197200 return R . cond ( [
198201 [ isString , parseStringType ] ,
@@ -213,10 +216,10 @@ function parseType(context) {
213216}
214217
215218// Returns whether the given element value matches the provided schema type
216- const valueMatchesType = ( type , value ) => {
219+ const valueMatchesType = R . curry ( ( value , type ) => {
217220 const expectedElementType = typeToElementNameMap [ type ] ;
218221 return value . element === expectedElementType ;
219- } ;
222+ } ) ;
220223
221224// Returns whether the given element value matches an enumeration of fixed values
222225const valueMatchesEnumerationValues = ( enumeration , value ) => {
@@ -240,9 +243,10 @@ function validateValuesMatchSchema(context, schema) {
240243 }
241244
242245 const type = schema . getValue ( 'type' ) ;
243- if ( type && ! valueMatchesType ( type , member . value ) ) {
246+ if ( type && R . none ( valueMatchesType ( member . value ) , type ) ) {
247+ const types = type . map ( t => `'${ t } '` ) . join ( ', ' ) ;
244248 return createWarning ( namespace ,
245- `'${ name } ' '${ member . key . toValue ( ) } ' does not match expected type ' ${ type } ' ` , member . value ) ;
249+ `'${ name } ' '${ member . key . toValue ( ) } ' does not match expected type ${ types } ` , member . value ) ;
246250 }
247251
248252 return member ;
@@ -375,10 +379,11 @@ function parseSchema(context) {
375379 element = constValue ;
376380 } else if ( enumerations ) {
377381 element = enumerations ;
382+ } else if ( type . length === 1 || ( type . length === 2 && type . includes ( 'null' ) ) ) {
383+ const findType = R . find ( R . complement ( R . equals ( 'nullable' ) ) ) ;
384+ element = constructStructure ( namespace , schema , findType ( type ) ) ;
378385 } else if ( type . length > 1 ) {
379386 throw new Error ( 'Implementation error: unexpected multiple types' ) ;
380- } else if ( type . length === 1 ) {
381- element = constructStructure ( namespace , schema , type [ 0 ] ) ;
382387 } else {
383388 element = new namespace . elements . Enum ( ) ;
384389 element . enumerations = [
@@ -404,8 +409,9 @@ function parseSchema(context) {
404409 element . description = description ;
405410 }
406411
412+ // On OAS 3.0, nullable is a keyword, on OAS 3.1, null goes in type
407413 const nullable = schema . getValue ( 'nullable' ) ;
408- if ( nullable ) {
414+ if ( nullable || ( type . includes ( 'null' ) && element . element !== 'null' ) ) {
409415 const typeAttributes = element . attributes . get ( 'typeAttributes' ) || new namespace . elements . Array ( ) ;
410416 typeAttributes . push ( 'nullable' ) ;
411417 element . attributes . set ( 'typeAttributes' , typeAttributes ) ;
0 commit comments