OpenAPITools / OpenAPITools/openapi-generator
[BUG] Strange conversion to camel case
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
Attribute names that include upper case letters are not being converted to camel case correctly.
This affectes model attributes, model names etc.
This can be demostrated through a lambda in a mustache template:
1. id {{#lambda.camelcase}}id{{/lambda.camelcase}}
2. ID {{#lambda.camelcase}}ID{{/lambda.camelcase}}
3. id_more {{#lambda.camelcase}}id_more{{/lambda.camelcase}}
4. ID_MORE {{#lambda.camelcase}}ID_MORE{{/lambda.camelcase}}
This results in:
1. id id
2. ID iD
3. id_more idMore
4. ID_MORE iDMORE
I believe 2 and 4 are wrong. For 2, the upper-case token should be treated as one word, so should be converted to lower case: "id".
For 4, there are two words, but of which should be converted to lower case, then concatenated with the second work capitalised: "idMore".
The model data supplied to the templates does the same conversion to an "ID" in the OpenAPI description, giving this:
{
"openApiType" : "integer",
"baseName" : "ID", <<<
"getter" : "getID", <<<
"setter" : "setID", <<<
"dataType" : "int",
"datatypeWithEnum" : "int",
"dataFormat" : "int32",
"name" : "iD", <<<
...
}
Here I would expect to see "ID", "getId", "setId" and "id".
openapi-generator version
The latest CLI docker container openapitools/openapi-generator-cli
5.0.0-SNAPSHOT
OpenAPI declaration file content or url
This shows the same effect, in any mustache template you like:
1. id {{#lambda.camelcase}}id{{/lambda.camelcase}}
2. ID {{#lambda.camelcase}}ID{{/lambda.camelcase}}
3. id_more {{#lambda.camelcase}}id_more{{/lambda.camelcase}}
4. ID_MORE {{#lambda.camelcase}}ID_MORE{{/lambda.camelcase}}
Or any OpenAPI description with an UPPERCASE property name.
Command line used for generation
docker run --rm openapitools/openapi-generator-cli ...
Steps to reproduce
See above.
Related issues/PRs
Not been able to find any.
Suggest a fix
I'm not a Java guy, and have tried and failed to set up an environment in the past, so can do nothing to help.
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 locating the camelcase lambda used by the Mustache templates and the model data conversion that produces the name, getter, and setter fields. Reproduce the four inputs from the issue, then verify that uppercase tokens produce the expected lowercase and capitalized forms in generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100