Skip to content

Commit c961863

Browse files
committed
setup spec
1 parent 3e7be5c commit c961863

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/src/Convertor.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const complexPropertyDefinitionSchema = require('../schemas/complex-propertyDefi
2121
const complexResolvedDefinitionSchema = require('../schemas/complex-resolvedDefinition')
2222
const complexNullTypeSchema = require('../schemas/complex-null')
2323
const complexTypeArraySchema = require('../schemas/complex-typeArray')
24+
const complexDefaultValuesSchema = require('../schemas/complex-defaultValues')
2425

2526
const simpleOpenAPI = require('../openAPI/simple')
2627

@@ -41,6 +42,7 @@ describe('Convertor', () => {
4142
delete require.cache[require.resolve('../schemas/complex-resolvedDefinition')];
4243
delete require.cache[require.resolve('../schemas/complex-null')];
4344
delete require.cache[require.resolve('../schemas/complex-typeArray')];
45+
delete require.cache[require.resolve('../schemas/complex-defaultValues')];
4446
convertor = new Convertor(simpleSchema)
4547
});
4648

@@ -416,6 +418,29 @@ describe('Convertor', () => {
416418
});
417419
});
418420

421+
describe('convert a schema with default values that are incorrectly defined', () => {
422+
it('should return a schema valid for OpenAPI v3.0.0', async function() {
423+
const complexConvertor = new Convertor(complexDefaultValuesSchema)
424+
const components = complexConvertor.convert()
425+
426+
const cloned = JSON.parse(JSON.stringify(simpleOpenAPI))
427+
let valid = await validator.validateInner(cloned, {})
428+
expect(valid).to.be.true
429+
Object.assign(cloned, {components})
430+
expect(cloned).to.have.property('components')
431+
expect(cloned.components).to.have.property('schemas')
432+
expect(cloned.components.schemas).to.have.property('main')
433+
expect(cloned.components.schemas.main).to.not.have.property('definitions')
434+
expect(cloned.components.schemas.main.properties.Price.default).to.be.equal(100)
435+
expect(cloned.components.schemas.main.properties.hasPrice.default).to.be.true
436+
valid = await validator.validateInner(cloned, {})
437+
.catch(err => {
438+
console.log(err)
439+
})
440+
expect(valid).to.be.true
441+
});
442+
});
443+
419444
describe('use a repo with lots of schemas to find failing ones', () => {
420445
xit('should convert all schemas successfully', async function() {
421446
this.timeout(5000);

0 commit comments

Comments
 (0)