@@ -53,6 +53,11 @@ const listOfBannedSchemas = require('../schemas/SchemasThatCannotBeConverted/lis
5353// anyOf/oneOf Nulls
5454const oneOfNull = require ( '../schemas/ofNulls/oneOfNull.json' )
5555const anyOfNull = require ( '../schemas/ofNulls/anyOfNull.json' )
56+ // anyOf/oneOf Nulls
57+ const allOfProperties = require ( '../schemas/propertiesOutsideOf/allOf.json' )
58+ const oneOfProperties = require ( '../schemas/propertiesOutsideOf/oneOf.json' )
59+ const anyOfProperties = require ( '../schemas/propertiesOutsideOf/anyOf.json' )
60+
5661
5762// OpenAPI
5863const basicOpenAPI = require ( '../openAPI/basic.json' )
@@ -633,6 +638,67 @@ describe('Convertor', () => {
633638 } ) ;
634639 } ) ;
635640
641+ describe ( `properties that exist outside of a oneOf|anyOf|allOf` , function ( ) {
642+ it ( `should put the property outside of an oneOf into the oneOf` , async function ( ) {
643+ const newConvertor = new Convertor ( oneOfProperties )
644+ const result = newConvertor . convert ( 'basic' )
645+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'oneOf' )
646+ expect ( result . schemas . basic . properties . payment . oneOf ) . to . be . an ( 'array' )
647+ expect ( result . schemas . basic . properties . payment . oneOf . length ) . to . be . equal ( 1 )
648+ expect ( result . schemas . basic . properties . payment ) . to . not . have . property ( 'default' )
649+ expect ( result . schemas . basic . properties . payment . oneOf [ 0 ] ) . to . have . property ( 'default' )
650+ expect ( result . schemas . basic . properties . payment . oneOf [ 0 ] . default ) . to . be . equal ( 'one' )
651+
652+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
653+ Object . assign ( cloned , { components : result } )
654+ expect ( cloned ) . to . have . property ( 'components' )
655+ expect ( cloned . components ) . to . have . property ( 'schemas' )
656+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
657+ let valid = await validator . validateInner ( cloned , { } )
658+ expect ( valid ) . to . be . true
659+ } ) ;
660+
661+ it ( `should put the property outside of an anyOf into the anyOf` , async function ( ) {
662+ const newConvertor = new Convertor ( anyOfProperties )
663+ const result = newConvertor . convert ( 'basic' )
664+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'anyOf' )
665+ expect ( result . schemas . basic . properties . payment . anyOf ) . to . be . an ( 'array' )
666+ expect ( result . schemas . basic . properties . payment . anyOf . length ) . to . be . equal ( 2 )
667+ expect ( result . schemas . basic . properties . payment ) . to . not . have . property ( 'default' )
668+ expect ( result . schemas . basic . properties . payment . anyOf [ 0 ] ) . to . have . property ( 'default' )
669+ expect ( result . schemas . basic . properties . payment . anyOf [ 0 ] . default ) . to . be . equal ( 'one' )
670+ expect ( result . schemas . basic . properties . payment . anyOf [ 1 ] ) . to . have . property ( 'default' )
671+ expect ( result . schemas . basic . properties . payment . anyOf [ 1 ] . default ) . to . be . equal ( 1 )
672+
673+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
674+ Object . assign ( cloned , { components : result } )
675+ expect ( cloned ) . to . have . property ( 'components' )
676+ expect ( cloned . components ) . to . have . property ( 'schemas' )
677+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
678+ let valid = await validator . validateInner ( cloned , { } )
679+ expect ( valid ) . to . be . true
680+ } ) ;
681+
682+ it ( `should put the property outside of an allOf into the allOf` , async function ( ) {
683+ const newConvertor = new Convertor ( allOfProperties )
684+ const result = newConvertor . convert ( 'basic' )
685+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'allOf' )
686+ expect ( result . schemas . basic . properties . payment . allOf ) . to . be . an ( 'array' )
687+ expect ( result . schemas . basic . properties . payment . allOf . length ) . to . be . equal ( 1 )
688+ expect ( result . schemas . basic . properties . payment ) . to . not . have . property ( 'default' )
689+ expect ( result . schemas . basic . properties . payment . allOf [ 0 ] ) . to . have . property ( 'default' )
690+ expect ( result . schemas . basic . properties . payment . allOf [ 0 ] . default ) . to . be . equal ( 'one' )
691+
692+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
693+ Object . assign ( cloned , { components : result } )
694+ expect ( cloned ) . to . have . property ( 'components' )
695+ expect ( cloned . components ) . to . have . property ( 'schemas' )
696+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
697+ let valid = await validator . validateInner ( cloned , { } )
698+ expect ( valid ) . to . be . true
699+ } ) ;
700+ } ) ;
701+
636702 xdescribe ( 'use a repo with lots of schemas to find failing ones' , ( ) => {
637703 it ( 'should convert all schemas successfully' , async function ( ) {
638704 this . timeout ( 1000000 ) ;
0 commit comments