Skip to content

Commit 8014c9c

Browse files
committed
new tests
1 parent 716468a commit 8014c9c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/src/Convertor.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const camelCased = require('../schemas/camelCasedKey/camelCasedKey.json')
5050
const arrayKeyOneOf = require('../schemas/arrayKeys/arrayKeyOneOf.json')
5151
// External Schemas That I Cannot Currently Convert
5252
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')
5356

5457
// OpenAPI
5558
const basicOpenAPI = require('../openAPI/basic.json')
@@ -604,6 +607,40 @@ describe('Convertor', () => {
604607
});
605608
});
606609

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+
607644
xdescribe('use a repo with lots of schemas to find failing ones', () => {
608645
it('should convert all schemas successfully', async function() {
609646
this.timeout(1000000);

0 commit comments

Comments
 (0)