@@ -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' )
@@ -381,9 +384,9 @@ describe('Convertor', () => {
381
384
const result = newConvertor . convert ( 'basic' )
382
385
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
383
386
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
384
- // expect(result.schemas.basic.properties.names.type ).to.be.equal('array ')
385
- // expect(result.schemas.basic.properties.names.items ).to.be.an('object ')
386
- // expect(result.schemas.basic.properties.names.items ).to.not. be.an('array' )
387
+ expect ( result . schemas . basic ) . to . have . property ( 'oneOf ')
388
+ expect ( result . schemas . basic . oneOf ) . to . be . an ( 'array ' )
389
+ expect ( result . schemas . basic . oneOf . length ) . to . be . equal ( 2 )
387
390
388
391
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
389
392
Object . assign ( cloned , { components : result } )
@@ -399,9 +402,9 @@ describe('Convertor', () => {
399
402
const result = newConvertor . convert ( 'basic' )
400
403
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
401
404
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
402
- // expect(result.schemas.basic.properties.names.type ).to.be.equal('array ')
403
- // expect(result.schemas.basic.properties.names.items ).to.be.an('object ')
404
- // expect(result.schemas.basic.properties.names.items ).to.not. be.an('array' )
405
+ expect ( result . schemas . basic ) . to . have . property ( 'oneOf ')
406
+ expect ( result . schemas . basic . oneOf ) . to . be . an ( 'array ' )
407
+ expect ( result . schemas . basic . oneOf . length ) . to . be . equal ( 1 )
405
408
406
409
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
407
410
Object . assign ( cloned , { components : result } )
@@ -417,9 +420,9 @@ describe('Convertor', () => {
417
420
const result = newConvertor . convert ( 'basic' )
418
421
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
419
422
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
420
- // expect(result.schemas.basic.properties.names.type ).to.be.equal('array ')
421
- // expect(result.schemas.basic.properties.names.items ).to.be.an('object ')
422
- // expect(result.schemas.basic.properties.names.items ).to.not. be.an('array' )
423
+ expect ( result . schemas . basic ) . to . have . property ( 'oneOf ')
424
+ expect ( result . schemas . basic . oneOf ) . to . be . an ( 'array ' )
425
+ expect ( result . schemas . basic . oneOf . length ) . to . be . equal ( 1 )
423
426
424
427
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
425
428
Object . assign ( cloned , { components : result } )
@@ -435,9 +438,7 @@ describe('Convertor', () => {
435
438
const result = newConvertor . convert ( 'basic' )
436
439
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
437
440
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
438
- // expect(result.schemas.basic.properties.names.type).to.be.equal('array')
439
- // expect(result.schemas.basic.properties.names.items).to.be.an('object')
440
- // expect(result.schemas.basic.properties.names.items).to.not.be.an('array')
441
+ expect ( result . schemas . basic ) . to . not . have . property ( 'oneOf' )
441
442
442
443
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
443
444
Object . assign ( cloned , { components : result } )
@@ -453,9 +454,7 @@ describe('Convertor', () => {
453
454
const result = newConvertor . convert ( 'basic' )
454
455
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
455
456
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
456
- // expect(result.schemas.basic.properties.names.type).to.be.equal('array')
457
- // expect(result.schemas.basic.properties.names.items).to.be.an('object')
458
- // expect(result.schemas.basic.properties.names.items).to.not.be.an('array')
457
+ expect ( result . schemas . basic ) . to . not . have . property ( 'oneOf' )
459
458
460
459
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
461
460
Object . assign ( cloned , { components : result } )
@@ -471,9 +470,7 @@ describe('Convertor', () => {
471
470
const result = newConvertor . convert ( 'basic' )
472
471
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
473
472
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
474
- // expect(result.schemas.basic.properties.names.type).to.be.equal('array')
475
- // expect(result.schemas.basic.properties.names.items).to.be.an('object')
476
- // expect(result.schemas.basic.properties.names.items).to.not.be.an('array')
473
+ expect ( result . schemas . basic ) . to . not . have . property ( 'oneOf' )
477
474
478
475
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
479
476
Object . assign ( cloned , { components : result } )
@@ -489,9 +486,7 @@ describe('Convertor', () => {
489
486
const result = newConvertor . convert ( 'basic' )
490
487
expect ( result . schemas . basic . properties ) . to . have . property ( 'street_address' )
491
488
expect ( result . schemas . basic . properties ) . to . have . property ( 'country' )
492
- // expect(result.schemas.basic.properties.names.type).to.be.equal('array')
493
- // expect(result.schemas.basic.properties.names.items).to.be.an('object')
494
- // expect(result.schemas.basic.properties.names.items).to.not.be.an('array')
489
+ expect ( result . schemas . basic ) . to . not . have . property ( 'oneOf' )
495
490
496
491
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
497
492
Object . assign ( cloned , { components : result } )
@@ -604,6 +599,40 @@ describe('Convertor', () => {
604
599
} ) ;
605
600
} ) ;
606
601
602
+ describe ( 'anyOf and oneOf with an object of type null' , ( ) => {
603
+ it ( 'should convert an anyOf with a type of null' , async function ( ) {
604
+ const newConvertor = new Convertor ( anyOfNull )
605
+ const result = newConvertor . convert ( 'basic' )
606
+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'anyOf' )
607
+ expect ( result . schemas . basic . properties . payment . anyOf ) . to . be . an ( 'array' )
608
+ expect ( result . schemas . basic . properties . payment . anyOf . length ) . to . be . equal ( 1 )
609
+
610
+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
611
+ Object . assign ( cloned , { components : result } )
612
+ expect ( cloned ) . to . have . property ( 'components' )
613
+ expect ( cloned . components ) . to . have . property ( 'schemas' )
614
+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
615
+ let valid = await validator . validateInner ( cloned , { } )
616
+ expect ( valid ) . to . be . true
617
+ } ) ;
618
+
619
+ it ( 'should convert a oneOf with a type of null' , async function ( ) {
620
+ const newConvertor = new Convertor ( oneOfNull )
621
+ const result = newConvertor . convert ( 'basic' )
622
+ expect ( result . schemas . basic . properties . payment ) . to . have . property ( 'oneOf' )
623
+ expect ( result . schemas . basic . properties . payment . oneOf ) . to . be . an ( 'array' )
624
+ expect ( result . schemas . basic . properties . payment . oneOf . length ) . to . be . equal ( 1 )
625
+
626
+ const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) )
627
+ Object . assign ( cloned , { components : result } )
628
+ expect ( cloned ) . to . have . property ( 'components' )
629
+ expect ( cloned . components ) . to . have . property ( 'schemas' )
630
+ expect ( cloned . components . schemas ) . to . have . property ( 'basic' )
631
+ let valid = await validator . validateInner ( cloned , { } )
632
+ expect ( valid ) . to . be . true
633
+ } ) ;
634
+ } ) ;
635
+
607
636
xdescribe ( 'use a repo with lots of schemas to find failing ones' , ( ) => {
608
637
it ( 'should convert all schemas successfully' , async function ( ) {
609
638
this . timeout ( 1000000 ) ;
0 commit comments