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

Support boolean additionalProperties in OpenAPI 2 #610

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/openapi2-parser/lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class DataStructureGenerator {
});
element.content.push(...requiredMembers);

if (schema.additionalProperties === false) {
const typeAttributes = element.attributes.get('typeAttributes') || new this.minim.elements.Array([]);
typeAttributes.push('fixed-type');
element.attributes.set('typeAttributes', typeAttributes);
}

return element;
}

Expand Down
30 changes: 30 additions & 0 deletions packages/openapi2-parser/test/schema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,36 @@ describe('JSON Schema to Data Structure', () => {
expect(samples).to.be.instanceof(ArrayElement);
expect(samples.toValue()).to.be.deep.equal([{ name: 'Doe' }]);
});

it('produces object with additionalProperties as true', () => {
const schema = {
type: 'object',
additionalProperties: true,
};

const dataStructure = schemaToDataStructure(schema);

expect(dataStructure.element).to.equal('dataStructure');
expect(dataStructure.content).to.be.instanceof(ObjectElement);

expect(dataStructure.content.length).to.equal(0);
expect(dataStructure.content.attributes.getValue('typeAttributes')).to.be.undefined;
});

it('produces object with additionalProperties as false', () => {
const schema = {
type: 'object',
additionalProperties: false,
};

const dataStructure = schemaToDataStructure(schema);

expect(dataStructure.element).to.equal('dataStructure');
expect(dataStructure.content).to.be.instanceof(ObjectElement);

expect(dataStructure.content.length).to.equal(0);
expect(dataStructure.content.attributes.getValue('typeAttributes')).to.deep.equal(['fixed-type']);
});
});

context('array schema', () => {
Expand Down