From 9a6bd35df704a6dc4de1c17f8c2e8231987261ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 16 Oct 2014 13:49:58 +0200 Subject: [PATCH] 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'. --- lib/model-helper.js | 9 ++++++--- test/model-helper.test.js | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/model-helper.js b/lib/model-helper.js index 51fbf53..598f0f1 100644 --- a/lib/model-helper.js +++ b/lib/model-helper.js @@ -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; }, diff --git a/test/model-helper.test.js b/test/model-helper.test.js index b183400..1fb6414 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -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.