model-helper: support anonymous object types

Accepts/returns arguments allow anonymous object types, e.g.

    { 'arg': 'kvp', type: { 'name': 'string', 'value': 'string' } }

As of this commit, these types are converted to Swagger type 'object'.
This commit is contained in:
Miroslav Bajtoš 2014-10-16 13:49:58 +02:00
parent aa7cb0b118
commit 9a6bd35df7
2 changed files with 13 additions and 3 deletions

View File

@ -121,9 +121,12 @@ var modelHelper = module.exports = {
if (typeof propType === 'function') {
// See https://github.com/strongloop/loopback-explorer/issues/32
// The type can be a model class
propType = propType.modelName || propType.name.toLowerCase();
} else if(Array.isArray(propType)) {
propType = 'array';
return propType.modelName || propType.name.toLowerCase();
} else if (Array.isArray(propType)) {
return 'array';
} else if (typeof propType === 'object') {
// Anonymous objects, they are allowed e.g. in accepts/returns definitions
return 'object';
}
return propType;
},

View File

@ -214,6 +214,13 @@ describe('model-helper', function() {
expect(def.properties).to.have.property('visibleProperty');
});
});
describe('getPropType', function() {
it('converts anonymous object types', function() {
var type = modelHelper.getPropType({ name: 'string', value: 'string' });
expect(type).to.eql('object');
});
});
});
// Simulates the format of a remoting class.