diff --git a/index.js b/index.js index 6a41724..e96d425 100644 --- a/index.js +++ b/index.js @@ -739,22 +739,23 @@ prototype.buildSecurityDefinitions = function(oldAuthorizations) { prototype.buildModel = function(oldModel) { var required = []; var properties = {}; + var items; this.forEach(oldModel.properties, function(oldProperty, propertyName) { if (fixNonStringValue(oldProperty.required) === true) { required.push(propertyName); } - properties[propertyName] = extend({}, - this.buildDataType(oldProperty, true), - { - description: oldProperty.description, - example: oldProperty.example - } - ); + properties[propertyName] = this.buildModel(oldProperty); }); - required = oldModel.required || required; + if (Array.isArray(oldModel.required)) { + required = oldModel.required; + } + + if (isValue(oldModel.items)) { + items = this.buildModel(oldModel.items); + } return extend(this.buildDataType(oldModel, true), { @@ -762,7 +763,8 @@ prototype.buildModel = function(oldModel) { required: undefinedIfEmpty(required), properties: undefinedIfEmpty(properties), discriminator: oldModel.discriminator, - example: oldModel.example + example: oldModel.example, + items: undefinedIfEmpty(items), }); }; diff --git a/test/input/complex-models/projects.json b/test/input/complex-models/projects.json index d97798a..d04ddee 100644 --- a/test/input/complex-models/projects.json +++ b/test/input/complex-models/projects.json @@ -52,6 +52,33 @@ "id": { "type": "integer", "description": "Project ID" + }, + "assigned": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "description": "Employee ID" + }, + "email": { + "type": "string" + } + } + }, + "subProjects": { + "type": "array", + "items": { + "type": "object", + "properties": { + "finished": { + "type": "boolean" + }, + "id": { + "type": "integer", + "description": "Project ID" + } + } + } } }, "description": "A Project object.", @@ -60,4 +87,4 @@ } } } -} \ No newline at end of file +} diff --git a/test/output/complex-models.json b/test/output/complex-models.json index 7bc3064..0952813 100644 --- a/test/output/complex-models.json +++ b/test/output/complex-models.json @@ -6,9 +6,36 @@ "id": 1337 }, "properties": { + "assigned": { + "properties": { + "email": { + "type": "string" + }, + "id": { + "description": "Employee ID", + "type": "integer" + } + }, + "type": "object" + }, "id": { "description": "Project ID", "type": "integer" + }, + "subProjects": { + "items": { + "properties": { + "finished": { + "type": "boolean" + }, + "id": { + "description": "Project ID", + "type": "integer" + } + }, + "type": "object" + }, + "type": "array" } }, "required": [