From 84e9486062beff1249f07433a2d3ba429ff791aa Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Sun, 20 Jul 2014 20:04:10 -0500 Subject: [PATCH] Properly convert complex return types. Attached tests. --- lib/route-helper.js | 10 ++++++---- test/route-helper.test.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/route-helper.js b/lib/route-helper.js index ce65cc2..263bbd2 100644 --- a/lib/route-helper.js +++ b/lib/route-helper.js @@ -124,7 +124,9 @@ var routeHelper = module.exports = { var apiDoc = { path: routeHelper.convertPathFragments(route.path), - operations: [{ + // Create the operation doc. Use `extendWithType` to add the necessary + // `items` and `format` fields. + operations: [routeHelper.extendWithType({ method: routeHelper.convertVerb(route.verb), // [rfeng] Swagger UI doesn't escape '.' for jQuery selector nickname: route.method.replace(/\./g, '_'), @@ -137,10 +139,10 @@ var routeHelper = module.exports = { responseMessages: [], summary: route.description, // TODO(schoon) - Excerpt? notes: '' // TODO(schoon) - `description` metadata? - }] + })] }; - // Convert types and return. - return routeHelper.extendWithType(apiDoc); + + return apiDoc; }, convertPathFragments: function convertPathFragments(path) { diff --git a/test/route-helper.test.js b/test/route-helper.test.js index d356fef..396007c 100644 --- a/test/route-helper.test.js +++ b/test/route-helper.test.js @@ -53,6 +53,28 @@ describe('route-helper', function() { expect(paramDoc.format).to.equal('byte'); }); + it('correctly converts return types (arrays)', function() { + var doc = createAPIDoc({ + returns: [ + {arg: 'data', type: ['customType']} + ] + }); + var opDoc = doc.operations[0]; + expect(opDoc.type).to.equal('array'); + expect(opDoc.items).to.eql({type: 'customType'}); + }); + + it('correctly converts return types (format)', function() { + var doc = createAPIDoc({ + returns: [ + {arg: 'data', type: 'buffer'} + ] + }); + var opDoc = doc.operations[0]; + expect(opDoc.type).to.equal('string'); + expect(opDoc.format).to.equal('byte'); + }); + }); // Easy wrapper around createRoute