Protected against non-Model generation requests
This commit is contained in:
parent
7f4e8b3f87
commit
fd30b2d151
|
@ -24,10 +24,8 @@ var modelHelper = module.exports = {
|
||||||
modelName = modelName.replace(/[\[\]]/g, '');
|
modelName = modelName.replace(/[\[\]]/g, '');
|
||||||
}
|
}
|
||||||
var model = app.models[modelName];
|
var model = app.models[modelName];
|
||||||
if (model) {
|
if (model && referencedModels.indexOf(model) === -1) {
|
||||||
if (referencedModels.indexOf(model) === -1) {
|
referencedModels.push(model);
|
||||||
referencedModels.push(model);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +47,7 @@ var modelHelper = module.exports = {
|
||||||
for (var m in def.settings.models) {
|
for (var m in def.settings.models) {
|
||||||
var model = modelClass[m];
|
var model = modelClass[m];
|
||||||
if (typeof model === 'function' && model.modelName) {
|
if (typeof model === 'function' && model.modelName) {
|
||||||
if (referencedModels.indexOf(model) === -1) {
|
if (model && referencedModels.indexOf(model) === -1) {
|
||||||
referencedModels.push(model);
|
referencedModels.push(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,15 +111,11 @@ var modelHelper = module.exports = {
|
||||||
// Generate model definitions for related models
|
// Generate model definitions for related models
|
||||||
for (var r in modelClass.relations) {
|
for (var r in modelClass.relations) {
|
||||||
var rel = modelClass.relations[r];
|
var rel = modelClass.relations[r];
|
||||||
if (rel.modelTo){
|
if (rel.modelTo && referencedModels.indexOf(rel.modelTo) === -1) {
|
||||||
if (referencedModels.indexOf(rel.modelTo) === -1) {
|
referencedModels.push(rel.modelTo);
|
||||||
referencedModels.push(rel.modelTo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (rel.modelThrough) {
|
if (rel.modelThrough && referencedModels.indexOf(rel.modelThrough) === -1) {
|
||||||
if (referencedModels.indexOf(rel.modelThrough) === -1) {
|
referencedModels.push(rel.modelThrough);
|
||||||
referencedModels.push(rel.modelThrough);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +145,9 @@ var modelHelper = module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0, n = referencedModels.length; i < n; i++) {
|
for (var i = 0, n = referencedModels.length; i < n; i++) {
|
||||||
generateModelDefinition(referencedModels[i], out);
|
if (referencedModels[i].definition) {
|
||||||
|
generateModelDefinition(referencedModels[i], out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
|
@ -161,7 +157,7 @@ var modelHelper = module.exports = {
|
||||||
* get a string type.
|
* get a string type.
|
||||||
* @param {*} propType Prop type description.
|
* @param {*} propType Prop type description.
|
||||||
* @return {String} Prop type string.
|
* @return {String} Prop type string.
|
||||||
*/
|
*/
|
||||||
getPropType: function getPropType(propType) {
|
getPropType: function getPropType(propType) {
|
||||||
if (typeof propType === 'function') {
|
if (typeof propType === 'function') {
|
||||||
// See https://github.com/strongloop/loopback-explorer/issues/32
|
// See https://github.com/strongloop/loopback-explorer/issues/32
|
||||||
|
@ -174,7 +170,7 @@ var modelHelper = module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
isHiddenProperty: function(definition, propName) {
|
isHiddenProperty: function(definition, propName) {
|
||||||
return definition.settings &&
|
return definition.settings &&
|
||||||
Array.isArray(definition.settings.hidden) &&
|
Array.isArray(definition.settings.hidden) &&
|
||||||
definition.settings.hidden.indexOf(propName) !== -1;
|
definition.settings.hidden.indexOf(propName) !== -1;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue