diff --git a/src/schema.js b/src/schema.js index cee7ff8..c920c81 100644 --- a/src/schema.js +++ b/src/schema.js @@ -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)) { diff --git a/test/schema.js b/test/schema.js index 2d05660..fee7f23 100644 --- a/test/schema.js +++ b/test/schema.js @@ -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']); + }); });