From bf3a2c9764392fe5d88cbef77f31d1bf37d0e88f Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 4 Aug 2014 23:22:41 -0700 Subject: [PATCH 1/2] Fix the type name for a property if model class is used See https://github.com/strongloop/loopback-explorer/issues/32 --- lib/model-helper.js | 4 +++- test/model-helper.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/model-helper.js b/lib/model-helper.js index e36ce6f..63f6ca0 100644 --- a/lib/model-helper.js +++ b/lib/model-helper.js @@ -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'; } diff --git a/test/model-helper.test.js b/test/model-helper.test.js index 0676767..e376a2a 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -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() { From b1fc7347ce4fb63005fcd8deb2bc4fddd361fb0c Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 8 Aug 2014 11:21:42 -0700 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 62ccc93..c5a0831 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-explorer", - "version": "1.2.7", + "version": "1.2.8", "description": "Browse and test your LoopBack app's APIs", "main": "index.js", "scripts": {