From a92450eaf05e85c48cf25d772ddf332428f78d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 22 Jul 2014 21:34:42 +0200 Subject: [PATCH 1/2] model-helper: handle array types with no item type --- lib/model-helper.js | 12 +++++++----- test/model-helper.test.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/model-helper.js b/lib/model-helper.js index 3b79297..b818222 100644 --- a/lib/model-helper.js +++ b/lib/model-helper.js @@ -79,12 +79,14 @@ var modelHelper = module.exports = { out.type = modelHelper.getPropType(out.type); if (out.type === 'array') { - var arrayProp = prop.type[0]; - if (!arrayProp.type) arrayProp = {type: arrayProp}; - out.items = modelHelper.LDLPropToSwaggerDataType(arrayProp); - } + var hasItemType = typeof prop.type !== 'string' && prop.type.length; - if (out.type === 'date') { + if (hasItemType) { + var arrayProp = prop.type[0]; + if (!arrayProp.type) arrayProp = {type: arrayProp}; + out.items = modelHelper.LDLPropToSwaggerDataType(arrayProp); + } + } else if (out.type === 'date') { out.type = 'string'; out.format = 'date'; } else if (out.type === 'buffer') { diff --git a/test/model-helper.test.js b/test/model-helper.test.js index 7bc8555..e13da9f 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -80,6 +80,22 @@ describe('model-helper', function() { type: 'string', format: 'date' }}); }); + + it('converts [] type', function() { + var def = getDefinition({ + array: [] + }); + var prop = def.properties.array; + expect(prop).to.eql({ type: 'array' }); + }); + + it('converts "array" type', function() { + var def = getDefinition({ + array: 'array' + }); + var prop = def.properties.array; + expect(prop).to.eql({ type: 'array' }); + }); }); }); }); From 6eb2dabf0c4a78d243bfed0ad03430ec768407fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 22 Jul 2014 21:46:00 +0200 Subject: [PATCH 2/2] 1.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf35529..998973b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-explorer", - "version": "1.2.2", + "version": "1.2.3", "description": "Browse and test your LoopBack app's APIs", "main": "index.js", "scripts": {