From 7ed64879cde4255f8959ee93f8d76f272febfde9 Mon Sep 17 00:00:00 2001 From: suchothendav Date: Wed, 10 Feb 2016 20:48:23 -0800 Subject: [PATCH] support unit tests for models with schema type as array #69 --- app/templates/_test_express.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/templates/_test_express.js b/app/templates/_test_express.js index 6e86735..d81d827 100644 --- a/app/templates/_test_express.js +++ b/app/templates/_test_express.js @@ -25,6 +25,7 @@ test('api', function (t) { <% var path = operation.path; var body; + var ref; var responseCode = operation.responses && Object.keys(operation.responses)[0]; var response = responseCode && operation.responses[responseCode]; var responseSchema = response && response.schema; @@ -46,8 +47,16 @@ test('api', function (t) { } }); } - if (param.in === 'body' && param.schema && param.schema.$ref) { - body = models[param.schema.$ref.slice(param.schema.$ref.lastIndexOf('/') + 1)]; + if (param.in === 'body' && param.schema ) { + ref = param.schema.$ref; + //If the schema type is array then the definition $ref will be items + if (param.schema.type === 'array' && param.schema.items) { + ref = param.schema.items.$ref; + } + //Skip if ref is undefined + if (ref) { + body = models[param.schema.$ref.slice(param.schema.$ref.lastIndexOf('/') + 1)]; + } } }); }