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.
This commit is contained in:
Samuel Reed 2014-11-10 11:10:50 +00:00
parent e9d990bf11
commit 8147ba5821
2 changed files with 18 additions and 3 deletions

View File

@ -149,8 +149,10 @@ var routeHelper = module.exports = {
// is specified in the first response message. // is specified in the first response message.
operations: [{ operations: [{
method: routeHelper.convertVerb(route.verb), method: routeHelper.convertVerb(route.verb),
// [rfeng] Swagger UI doesn't escape '.' for jQuery selector // [strml] remove leading model name from op, swagger uses leading
nickname: route.method.replace(/\./g, '_'), // path as class name so it remains unique between models.
// route.method is always #{className}.#{methodName}
nickname: route.method.replace(/.*?\./, ''),
parameters: accepts, parameters: accepts,
responseMessages: responseMessages, responseMessages: responseMessages,
summary: typeConverter.convertText(route.description), summary: typeConverter.convertText(route.description),

View File

@ -185,11 +185,24 @@ describe('route-helper', function() {
responseModel: 'ValidationError' 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 // Easy wrapper around createRoute
function createAPIDoc(def) { function createAPIDoc(def) {
return routeHelper.routeToAPIDoc(_defaults(def, { return routeHelper.routeToAPIDoc(_defaults(def || {}, {
path: '/test', path: '/test',
verb: 'GET', verb: 'GET',
method: 'test.get' method: 'test.get'