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:
parent
200da753b4
commit
bf3a2c9764
|
@ -83,7 +83,9 @@ var modelHelper = module.exports = {
|
||||||
*/
|
*/
|
||||||
getPropType: function getPropType(propType) {
|
getPropType: function getPropType(propType) {
|
||||||
if (typeof propType === 'function') {
|
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)) {
|
} else if(Array.isArray(propType)) {
|
||||||
propType = 'array';
|
propType = 'array';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var modelHelper = require('../lib/model-helper');
|
var modelHelper = require('../lib/model-helper');
|
||||||
|
var loopback = require('loopback');
|
||||||
var expect = require('chai').expect;
|
var expect = require('chai').expect;
|
||||||
|
|
||||||
describe('model-helper', function() {
|
describe('model-helper', function() {
|
||||||
|
@ -109,6 +110,17 @@ describe('model-helper', function() {
|
||||||
var prop = def.properties.array;
|
var prop = def.properties.array;
|
||||||
expect(prop).to.eql({ type: 'array', items: { type: 'any' } });
|
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() {
|
describe('related models', function() {
|
||||||
|
|
Loading…
Reference in New Issue