swagger-api / swagger-api/swagger-codegen
[nodejs-server] swagger-tools:router cannot find generated handler due to CapitalCase operationId value 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
Description
After starting a nodejs-server using NODE_ENV=development DEBUG=* npm start and making a request, swagger-tools:middleware:router informs me that the handler is missing. This issue is caused by the operationId in the swagger.yaml having a value that is CapitalCase when I think it should be camelCase. So the router is looking for a CapitalCase handler name but all the handlers are defined with camelCase.
// Example generated Handler code -- it is camelCase
module.exports.getUser = function getUser (req, res, next) {
Users.getUser(req.swagger.params, res, next);
};
// See third line: the router is looking for "GetUser" as CapitalCase
swagger-tools:middleware:router GET /api/users/abc +0ms
swagger-tools:middleware:router Will process: yes +0ms
swagger-tools:middleware:router Route handler: Users_GetUser +0ms
swagger-tools:middleware:router Missing: yes +1ms
swagger-tools:middleware:router Ignored: no +0ms
swagger-tools:middleware:router Using mock: yes +0ms
I have confirmed that changing the handler name to CapitalCase allows the router to find it. Alternatively, I also tried changing the operationId value in swagger.yaml to camelCase which is another way to fix the problem.
It looks like the default generated handlers are meant to be runnable as a basic mock when swagger-tools router mocking is turned off, but the router can't find them due to casing issue described above.
Swagger-codegen version
using docker image: swaggerapi/swagger-codegen-cli:latest @ v2.4.0-SNAPSHOT
Suggest a fix/enhancement
It seems like the swagger-codegen should be writing the swagger.yaml with camelCase like operationId: getUser, not CapitalCase.
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
Start by reproducing the request with NODE_ENV=development DEBUG=* npm start, then compare the operationId in swagger.yaml with the generated JavaScript handler name. Confirm that the router resolves the handler when casing matches, and add or update a regression test if the repository provides one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100