From 8147ba582133646acd4135a9dc53f88db9db401f Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Mon, 10 Nov 2014 11:10:50 +0000 Subject: [PATCH] Remove model name from nickname, swagger spec understands op context. This removes the redundancy from paths in swagger-ui such as `/api/user/user_login`. It will now be displayed simply as `/api/user/login`. This is consistent with how `nickname` is used in Swagger examples. Added tests to route nickname processing. --- lib/route-helper.js | 6 ++++-- test/route-helper.test.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/route-helper.js b/lib/route-helper.js index 98ea610..a5ba8d5 100644 --- a/lib/route-helper.js +++ b/lib/route-helper.js @@ -149,8 +149,10 @@ var routeHelper = module.exports = { // is specified in the first response message. operations: [{ method: routeHelper.convertVerb(route.verb), - // [rfeng] Swagger UI doesn't escape '.' for jQuery selector - nickname: route.method.replace(/\./g, '_'), + // [strml] remove leading model name from op, swagger uses leading + // path as class name so it remains unique between models. + // route.method is always #{className}.#{methodName} + nickname: route.method.replace(/.*?\./, ''), parameters: accepts, responseMessages: responseMessages, summary: typeConverter.convertText(route.description), diff --git a/test/route-helper.test.js b/test/route-helper.test.js index cfe2010..faca3a5 100644 --- a/test/route-helper.test.js +++ b/test/route-helper.test.js @@ -185,11 +185,24 @@ describe('route-helper', function() { responseModel: 'ValidationError' }); }); + + it('route nickname does not include model name.', function() { + var doc = createAPIDoc(); + expect(doc.operations[0].nickname).to.equal('get'); + }); + + it('route nickname with a period is shorted correctly', function() { + // Method is built by remoting to always be #{className}.#{methodName} + var doc = createAPIDoc({ + method: 'test.get.me' + }); + expect(doc.operations[0].nickname).to.eql('get.me'); + }); }); // Easy wrapper around createRoute function createAPIDoc(def) { - return routeHelper.routeToAPIDoc(_defaults(def, { + return routeHelper.routeToAPIDoc(_defaults(def || {}, { path: '/test', verb: 'GET', method: 'test.get'