@@ -22,6 +22,7 @@ const complexResolvedDefinitionSchema = require('../schemas/complex-resolvedDefi
2222const complexNullTypeSchema = require ( '../schemas/complex-null' )
2323const complexTypeArraySchema = require ( '../schemas/complex-typeArray' )
2424const complexDefaultValuesSchema = require ( '../schemas/complex-defaultValues' )
25+ const complexAdditionalPropertiesSchema = require ( '../schemas/complex-additionalProperties' )
2526
2627const simpleOpenAPI = require ( '../openAPI/simple' )
2728
@@ -43,6 +44,7 @@ describe('Convertor', () => {
4344 delete require . cache [ require . resolve ( '../schemas/complex-null' ) ] ;
4445 delete require . cache [ require . resolve ( '../schemas/complex-typeArray' ) ] ;
4546 delete require . cache [ require . resolve ( '../schemas/complex-defaultValues' ) ] ;
47+ delete require . cache [ require . resolve ( '../schemas/complex-additionalProperties' ) ] ;
4648 convertor = new Convertor ( simpleSchema )
4749 } ) ;
4850
@@ -441,6 +443,27 @@ describe('Convertor', () => {
441443 } ) ;
442444 } ) ;
443445
446+ describe ( 'convert a schema with additionalProperties containing refs' , ( ) => {
447+ it ( 'should return a schema valid for OpenAPI v3.0.0' , async function ( ) {
448+ const complexConvertor = new Convertor ( complexAdditionalPropertiesSchema )
449+ const components = complexConvertor . convert ( )
450+
451+ const cloned = JSON . parse ( JSON . stringify ( simpleOpenAPI ) )
452+ let valid = await validator . validateInner ( cloned , { } )
453+ expect ( valid ) . to . be . true
454+ Object . assign ( cloned , { components} )
455+ expect ( cloned ) . to . have . property ( 'components' )
456+ expect ( cloned . components ) . to . have . property ( 'schemas' )
457+ expect ( cloned . components . schemas ) . to . have . property ( 'main' )
458+ expect ( cloned . components . schemas . main ) . to . not . have . property ( 'definitions' )
459+ valid = await validator . validateInner ( cloned , { } )
460+ . catch ( err => {
461+ console . log ( err )
462+ } )
463+ expect ( valid ) . to . be . true
464+ } ) ;
465+ } ) ;
466+
444467 describe ( 'use a repo with lots of schemas to find failing ones' , ( ) => {
445468 xit ( 'should convert all schemas successfully' , async function ( ) {
446469 this . timeout ( 5000 ) ;
0 commit comments