From 4843a1f8d1b590c92ea9410d670208c3b56914ba Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Wed, 10 Apr 2019 17:43:00 -0700 Subject: [PATCH] fix(cli): generate operation only for the 1st tag to avoid duplicate routes An OpenAPI operation may have more than one tags. Adding the operation to two controllers produces duplicate routes and it fails the application. --- packages/cli/generators/openapi/spec-helper.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/generators/openapi/spec-helper.js b/packages/cli/generators/openapi/spec-helper.js index 239be4a947a6..517135f0735c 100644 --- a/packages/cli/generators/openapi/spec-helper.js +++ b/packages/cli/generators/openapi/spec-helper.js @@ -97,8 +97,9 @@ function groupOperationsByController(apiSpec) { let controllers = ['OpenApiController']; if (op['x-controller-name']) { controllers = [op['x-controller-name']]; - } else if (op.tags) { - controllers = op.tags.map(t => titleCase(t + 'Controller')); + } else if (Array.isArray(op.tags) && op.tags.length) { + // Only add the operation to first tag to avoid duplicate routes + controllers = [titleCase(op.tags[0] + 'Controller')]; } controllers.forEach((c, index) => { /**