OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][Spring] Spring generator generates invalid class names that start with numbers
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I downloaded the .jar on Windows and used it to generate a spring boot project. To my surprise, this project does not even compile (generation itself is successful). The reason is an edge case in the api definition: Some of the api urls start with a number (2faDevices, for example). The generated controller interface is then called 2faDevicesApiController, which is not a valid name for a class because it starts with a number. This should not be the default behaviour.
openapi-generator version
Version 6.2.1
Reproduction
I cannot provide concrete data to reproduce the issue, but anyone familiar with the tool should be able to easily reproduce it themselves.
Suggest a fix
There are two possible solutions:
- Prefix such names with a valid literal (like
N2fa, "N" for number) - write the name of the number out (like
Twofa
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
No source file or test is named. Start with the Spring generator and an OpenAPI definition containing a path or operation name beginning with a digit, then inspect the generated controller interface name. Done means the generated Java project uses valid class names and compiles for such inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100