Skip to content

Commit

Permalink
Merge pull request #72 from APIs-guru/master
Browse files Browse the repository at this point in the history
Improve conversion of sub-schemes.
  • Loading branch information
IvanGoncharov committed Feb 22, 2016
2 parents 56cdcb8 + 796e8f9 commit 675cccc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,30 +739,32 @@ 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),
{
description: oldModel.description,
required: undefinedIfEmpty(required),
properties: undefinedIfEmpty(properties),
discriminator: oldModel.discriminator,
example: oldModel.example
example: oldModel.example,
items: undefinedIfEmpty(items),
});
};

Expand Down
29 changes: 28 additions & 1 deletion test/input/complex-models/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -60,4 +87,4 @@
}
}
}
}
}
27 changes: 27 additions & 0 deletions test/output/complex-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 675cccc

Please sign in to comment.