swagger-api / swagger-api/swagger-codegen
Generated nodejs server does not include `x-swagger-router-controller` or `operationId` attributes in `swagger.yaml`
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
From @kmd-jamesgauld on January 20, 2016 13:59
Swagger Router middleware requires that a x-swagger-router-controller attribute be present to help route requests to the correct controller, and an operationId attribute to route to a specific method.
Currently, when exporting a nodejs server app, the editor does not include these attributes in the api/swagger.yaml file which, when making a request to the nodejs server, throws the following error:
Error: Cannot resolve the configured swagger-router handler: undefined
at swaggerRouter (/var/www/mock-api/node_modules/swagger-tools/middleware/swagger-router.js:414:18)
at call (/var/www/mock-api/node_modules/connect/index.js:239:7)
at next (/var/www/mock-api/node_modules/connect/index.js:183:5)
at /var/www/mock-api/node_modules/swagger-tools/middleware/swagger-validator.js:350:30
at /var/www/mock-api/node_modules/async/lib/async.js:52:16
at /var/www/mock-api/node_modules/async/lib/async.js:361:13
at /var/www/mock-api/node_modules/async/lib/async.js:52:16
at async.forEachOf.async.eachOf (/var/www/mock-api/node_modules/async/lib/async.js:236:30)
at _asyncMap (/var/www/mock-api/node_modules/async/lib/async.js:355:9)
at Object.map (/var/www/mock-api/node_modules/async/lib/async.js:337:20)
Partial yaml config:
...
paths:
/users:
get:
summary: "Get Users."
...
There exists a controllers/User.js file with relevant content:
...
module.exports.usersGet = function usersGet (req, res, next) {
User.usersGet(req.swagger.params, res, next);
};
...
Adding the missing attributes fixes the problem:
...
paths:
x-swagger-router-controller: User
/users:
get:
operationId: usersGet
summary: "Get Users."
...
Copied from original issue: swagger-api/swagger-editor#784
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Compare the generated api/swagger.yaml with controllers/User.js and trace how the Node.js server output is produced. Confirm that each generated path includes x-swagger-router-controller and each operation includes operationId, then verify the generated server can route the request without the reported handler error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100