OpenAPITools / OpenAPITools/openapi-generator
[BUG] [nodejs-express-server] Bug Generating Service with SnakeCase Parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [x ] Have you provided a full/minimal spec to reproduce the issue?
- [x ] Have you validated the input using an OpenAPI validator (example)?
- [x ] Have you tested with the latest master to confirm the issue still exists?
- [ x] Have you searched for related issues/PRs?
- [x ] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating a service, nodejs-express-server incorrectly names properties that have underscores in the name.
Expected: userId
Actual: userUnderscoreid
openapi-generator version
5.4.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
description: Service
title: Service
version: "1.0"
servers:
- description: dev server
url: http://localhost:8080
security:
- bearerAuth: []
paths:
/v1/users/{user_id}:
delete:
operationId: deleteUser
parameters:
- description: Identifier of user to delete
in: path
name: user_id
required: true
schema:
type: string
responses:
"200":
content: {}
description: Delete result
Generation Details
openapi-generator generate -i api-spec.yaml --package-name service -g nodejs-express-server -o ~/workplace/service
UsersService.ts
/**
* Delete a user
*
* userUnderscoreid String Identifier of user to return
* no response value expected for this operation
* */
const deleteUser = ({ userUnderscoreid }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
userUnderscoreid,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
Steps to reproduce
See above
Related issues/PRs
N/A
Suggest a fix
Utilize camelize when creating property names.
The root cause appears to be here, where underscore is not included in the pattern, where it is in the normal default.:
https://github.com/OpenAPITools/openapi-generator/blob/b6a8037f62a5e4244236b65518c9f5e6fd02f27e/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java#L414
Which then causes underscore to be renamed by special characters in this block here:
https://github.com/OpenAPITools/openapi-generator/blob/b6a8037f62a5e4244236b65518c9f5e6fd02f27e/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L1484
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 with modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java at the cited line, then compare the related handling in DefaultCodegen.java. Reproduce the issue with the YAML declaration and generator command from the report. Done means the generated UsersService.ts uses the expected userId parameter name instead of userUnderscoreid, with regression coverage if the relevant generator tests are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, java, node.js, openapi
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100