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:
commit
bf3f438a58
|
@ -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] = {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue