Swagger-codegen: Generated node server fails with: "Cannot resolve the configured swagger-router handler:"

Created on 23 Nov 2017  路  2Comments  路  Source: swagger-api/swagger-codegen

Description

Node server stub generated from Swagger 2.0 specification starts up fine, but throws an error on sending the request.

Here is the error log:

Error: Cannot resolve the configured swagger-router handler: Transactions_GET-transaction
    at swaggerRouter (C:\nodejs-server-server\node_modules\swagger-tools\middleware\swagger-router.js:414:18)
    at call (C:\nodejs-server-server\node_modules\connect\index.js:239:7)
    at next (C:\nodejs-server-server\node_modules\connect\index.js:183:5)
    at C:\nodejs-server-server\node_modules\swagger-tools\middleware\swagger-validator.js:352:30
    at C:\nodejs-server-server\node_modules\async\lib\async.js:52:16
    at C:\nodejs-server-server\node_modules\async\lib\async.js:361:13
    at C:\nodejs-server-server\node_modules\async\lib\async.js:52:16
    at async.forEachOf.async.eachOf (C:\nodejs-server-server\node_modules\async\lib\async.js:236:30)
    at _asyncMap (C:\nodejs-server-server\node_modules\async\lib\async.js:355:9)
    at Object.map (C:\nodejs-server-server\node_modules\async\lib\async.js:337:20)
Swagger-codegen version
Swagger declaration file content or url

https://app.swaggerhub.com/apis/RitwikChatterjee/transactions/1.0.1

Command line used for generation

Used editor.swagger.io and www.swaggerhub.com to download the generated server stub

Steps to reproduce
  1. Copy Swagger file into editor.swagger.io or www.swaggerhub.com
  2. Generate server -> Nodejs-server
  3. Save, extract and go to folder.
  4. Start server with npm start
  5. Hit http://localhost:8080/transactions/123
Related issues/PRs

None

Suggest a fix/enhancement

Looks like a dependency is broken. Not sure what though.

Most helpful comment

Using lower camel case for operation IDs fixed it for me.

All 2 comments

On Further investigation
Thanks to Natalie, she pointed me to this link https://github.com/apigee-127/swagger-tools/issues/321

However, here is what I found when I looked at the generated code:

  • I noticed that though the x-swagger-router-controller tag was not in my original definition, when codegen generated the code, it auto incorporated the same at the method level in the generated swagger.yaml file (/api/swagger.yaml).
  • While generating the code, codegen also generated its own controller function names.
  • While serving the requests the code was working as explained in here , i.e. it is expecting a controller function <x-swagger-router-controller>_<operationId> which was not available.

Manual workaround
I could fix the issue manually by updating the operationId in the generated swagger.yaml file to the function-name created by codegen.

Is this a bug?

Using lower camel case for operation IDs fixed it for me.

Was this page helpful?
0 / 5 - 0 ratings