@@ -50,6 +50,9 @@ const camelCased = require('../schemas/camelCasedKey/camelCasedKey.json')
50
50
const arrayKeyOneOf = require ( '../schemas/arrayKeys/arrayKeyOneOf.json' )
51
51
// External Schemas That I Cannot Currently Convert
52
52
const listOfBannedSchemas = require ( '../schemas/SchemasThatCannotBeConverted/list.json' )
53
+ // anyOf/oneOf Nulls
54
+ const oneOfNull = require ( '../schemas/ofNulls/oneOfNull.json' )
55
+ const anyOfNull = require ( '../schemas/ofNulls/anyOfNull.json' )
53
56
54
57
// OpenAPI
55
58
const basicOpenAPI = require ( '../openAPI/basic.json' )
@@ -604,6 +607,40 @@ describe('Convertor', () => {
604
607
} ) ;
605
608
} ) ;
606
609
610
+ describe ( 'anyOf and oneOf with an object of type null' , ( ) => {
611
+ it ( 'should convert an anyOf with a type of null' , async function ( ) {
612
+ const newConvertor = new Convertor ( anyOfNull )
613
+ const result = newConvertor . convert ( 'basic' )
614
+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'anyOf' )
615
+ expect ( result . schemas . basic . properties . payment . anyOf ) . to . be . an ( 'array' )
616
+ expect ( result . schemas . basic . properties . payment . anyOf . length ) . to . be . equal ( 1 )
617
+
618
+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
619
+ Object . assign ( cloned , { components : result } )
620
+ expect ( cloned ) . to . have . property ( 'components' )
621
+ expect ( cloned . components ) . to . have . property ( 'schemas' )
622
+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
623
+ let valid = await validator . validateInner ( cloned , { } )
624
+ expect ( valid ) . to . be . true
625
+ } ) ;
626
+
627
+ it ( 'should convert a oneOf with a type of null' , async function ( ) {
628
+ const newConvertor = new Convertor ( oneOfNull )
629
+ const result = newConvertor . convert ( 'basic' )
630
+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'oneOf' )
631
+ expect ( result . schemas . basic . properties . payment . oneOf ) . to . be . an ( 'array' )
632
+ expect ( result . schemas . basic . properties . payment . oneOf . length ) . to . be . equal ( 1 )
633
+
634
+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
635
+ Object . assign ( cloned , { components : result } )
636
+ expect ( cloned ) . to . have . property ( 'components' )
637
+ expect ( cloned . components ) . to . have . property ( 'schemas' )
638
+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
639
+ let valid = await validator . validateInner ( cloned , { } )
640
+ expect ( valid ) . to . be . true
641
+ } ) ;
642
+ } ) ;
643
+
607
644
xdescribe ( 'use a repo with lots of schemas to find failing ones' , ( ) => {
608
645
it ( 'should convert all schemas successfully' , async function ( ) {
609
646
this . timeout ( 1000000 ) ;
0 commit comments