Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit fd2584f

Browse files
committed
feat(oas2): support boolean additionalProperties
1 parent ef553d9 commit fd2584f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/openapi2-parser/lib/schema.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ class DataStructureGenerator {
120120
});
121121
element.content.push(...requiredMembers);
122122

123+
if (schema.additionalProperties === false) {
124+
const typeAttributes = element.attributes.get('typeAttributes') || new this.minim.elements.Array([]);
125+
typeAttributes.push('fixed-type');
126+
element.attributes.set('typeAttributes', typeAttributes);
127+
}
128+
123129
return element;
124130
}
125131

packages/openapi2-parser/test/schema-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,36 @@ describe('JSON Schema to Data Structure', () => {
692692
expect(samples).to.be.instanceof(ArrayElement);
693693
expect(samples.toValue()).to.be.deep.equal([{ name: 'Doe' }]);
694694
});
695+
696+
it('produces object with additionalProperties as true', () => {
697+
const schema = {
698+
type: 'object',
699+
additionalProperties: true,
700+
};
701+
702+
const dataStructure = schemaToDataStructure(schema);
703+
704+
expect(dataStructure.element).to.equal('dataStructure');
705+
expect(dataStructure.content).to.be.instanceof(ObjectElement);
706+
707+
expect(dataStructure.content.length).to.equal(0);
708+
expect(dataStructure.content.attributes.getValue('typeAttributes')).to.be.undefined;
709+
});
710+
711+
it('produces object with additionalProperties as false', () => {
712+
const schema = {
713+
type: 'object',
714+
additionalProperties: false,
715+
};
716+
717+
const dataStructure = schemaToDataStructure(schema);
718+
719+
expect(dataStructure.element).to.equal('dataStructure');
720+
expect(dataStructure.content).to.be.instanceof(ObjectElement);
721+
722+
expect(dataStructure.content.length).to.equal(0);
723+
expect(dataStructure.content.attributes.getValue('typeAttributes')).to.deep.equal(['fixed-type']);
724+
});
695725
});
696726

697727
context('array schema', () => {

0 commit comments

Comments
 (0)