Merge pull request #45 from clarkorz/feature/add-other-models

Make sure nested/referenced models in array are mapped to swagger
This commit is contained in:
Raymond Feng 2014-08-29 08:22:07 -07:00
commit bf3f438a58
2 changed files with 20 additions and 1 deletions

View File

@ -72,10 +72,18 @@ var modelHelper = module.exports = {
var propType = def.properties[key].type;
if (typeof propType === 'function' && propType.modelName) {
if (referencedModels.indexOf(m) === -1) {
if (referencedModels.indexOf(propType) === -1) {
referencedModels.push(propType);
}
}
if (Array.isArray(propType) && propType.length) {
var itemType = propType[0];
if (typeof itemType === 'function' && itemType.modelName) {
if (referencedModels.indexOf(itemType) === -1) {
referencedModels.push(itemType);
}
}
}
});
out[name] = {

View File

@ -153,6 +153,17 @@ describe('model-helper', function() {
expect(defs).has.property('Model3');
expect(defs).has.property('Model4');
});
it('should include nesting models in array', function() {
var Model6 = loopback.createModel('Model6', {street: String});
var Model5 = loopback.createModel('Model5', {
str: String, // 'string'
addresses: [Model6]
});
var defs = modelHelper.generateModelDefinition(Model5, {});
expect(defs).has.property('Model5');
expect(defs).has.property('Model6');
});
});
describe('hidden properties', function() {