@@ -18,6 +18,7 @@ const moreComplexOneOfSchema = require('../schemas/morecomplex-oneOf')
1818const complexPropertySchema = require ( '../schemas/complex-property' )
1919const complexPropertyDefinitionSchema = require ( '../schemas/complex-propertyDefinition' )
2020const complexResolvedDefinitionSchema = require ( '../schemas/complex-resolvedDefinition' )
21+ const complexNullTypeSchema = require ( '../schemas/complex-null' )
2122
2223const simpleOpenAPI = require ( '../openAPI/simple' )
2324
@@ -36,6 +37,7 @@ describe('Convertor', () => {
3637 delete require . cache [ require . resolve ( '../schemas/complex-property' ) ] ;
3738 delete require . cache [ require . resolve ( '../schemas/complex-propertyDefinition' ) ] ;
3839 delete require . cache [ require . resolve ( '../schemas/complex-resolvedDefinition' ) ] ;
40+ delete require . cache [ require . resolve ( '../schemas/complex-null' ) ] ;
3941 convertor = new Convertor ( simpleSchema )
4042 } ) ;
4143
@@ -369,4 +371,24 @@ describe('Convertor', () => {
369371 expect ( valid ) . to . be . true
370372 } ) ;
371373 } ) ;
374+
375+ describe ( 'convert a schema with null types' , ( ) => {
376+ it ( 'should return a schema valid for OpenAPI v3.0.0' , async function ( ) {
377+ const complexConvertor = new Convertor ( complexNullTypeSchema )
378+ const components = complexConvertor . convert ( )
379+ const cloned = JSON . parse ( JSON . stringify ( simpleOpenAPI ) )
380+ let valid = await validator . validateInner ( cloned , { } )
381+ expect ( valid ) . to . be . true
382+ Object . assign ( cloned , { components} )
383+ expect ( cloned ) . to . have . property ( 'components' )
384+ expect ( cloned . components ) . to . have . property ( 'schemas' )
385+ expect ( cloned . components . schemas ) . to . have . property ( 'main' )
386+ expect ( cloned . components . schemas . main ) . to . not . have . property ( 'definitions' )
387+ valid = await validator . validateInner ( cloned , { } )
388+ . catch ( err => {
389+ console . log ( err )
390+ } )
391+ expect ( valid ) . to . be . true
392+ } ) ;
393+ } ) ;
372394} ) ;
0 commit comments