Make sure nested/referenced models in array are mapped to swagger
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
This commit is contained in:
parent
d083feab36
commit
acf00f3254
|
@ -72,10 +72,18 @@ var modelHelper = module.exports = {
|
||||||
|
|
||||||
var propType = def.properties[key].type;
|
var propType = def.properties[key].type;
|
||||||
if (typeof propType === 'function' && propType.modelName) {
|
if (typeof propType === 'function' && propType.modelName) {
|
||||||
if (referencedModels.indexOf(m) === -1) {
|
if (referencedModels.indexOf(propType) === -1) {
|
||||||
referencedModels.push(propType);
|
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] = {
|
out[name] = {
|
||||||
|
|
|
@ -153,6 +153,17 @@ describe('model-helper', function() {
|
||||||
expect(defs).has.property('Model3');
|
expect(defs).has.property('Model3');
|
||||||
expect(defs).has.property('Model4');
|
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() {
|
describe('hidden properties', function() {
|
||||||
|
|
Loading…
Reference in New Issue