Fix the type name for a property if model class is used

See https://github.com/strongloop/loopback-explorer/issues/32
This commit is contained in:
Raymond Feng 2014-08-04 23:22:41 -07:00
parent 200da753b4
commit bf3a2c9764
2 changed files with 15 additions and 1 deletions

View File

@ -83,7 +83,9 @@ var modelHelper = module.exports = {
*/
getPropType: function getPropType(propType) {
if (typeof propType === 'function') {
propType = propType.name.toLowerCase();
// 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';
}

View File

@ -1,6 +1,7 @@
'use strict';
var modelHelper = require('../lib/model-helper');
var loopback = require('loopback');
var expect = require('chai').expect;
describe('model-helper', function() {
@ -109,6 +110,17 @@ describe('model-helper', function() {
var prop = def.properties.array;
expect(prop).to.eql({ type: 'array', items: { type: 'any' } });
});
it('converts Model type', function() {
var Address = loopback.createModel('Address', {street: String});
var def = buildSwaggerModels({
str: String,
address: Address
});
var prop = def.properties.address;
expect(prop).to.eql({ type: 'Address' });
});
});
});
describe('related models', function() {