Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Commit

Permalink
feat(schema): Support x-nullable in dataStructure generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Mar 14, 2018
1 parent 7e092d4 commit 987296e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export default class DataStructureGenerator {
element.description = new StringElement(schema.description);
}

if (schema['x-nullable']) {
element.attributes.set('typeAttributes', ['nullable']);
}

let def = schema.default;

if (def !== undefined && !_.isArray(def) && !_.isObject(def)) {
Expand Down
13 changes: 13 additions & 0 deletions test/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,17 @@ describe('JSON Schema to Data Structure', () => {

expect(dataStructure).to.be.null;
});

it('adds nullable typeAttribute with x-nullable extension', () => {
const schema = {
type: 'string',
'x-nullable': true,
};

const dataStructure = schemaToDataStructure(schema);

expect(dataStructure.element).to.equal('dataStructure');
expect(dataStructure.content).to.be.instanceof(StringElement);
expect(dataStructure.content.attributes.getValue('typeAttributes')).to.deep.equal(['nullable']);
});
});

0 comments on commit 987296e

Please sign in to comment.