question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Strange conversion to camel case

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

2reactions
judgejcommented, Nov 11, 2020

Is there a way to import a custom camel case lambda at runtime, and using that to produce desired conversion?

1reaction
blue00commented, Aug 19, 2020

I have the same problem with the typescript-angular converter using the option "modelPropertyNaming": "camelCase": “VAT” becomes “vAT”, but I expected it to become “vat”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Converting Snake Case to Lower Camel Case ...
The obvious solution is to split by underscore, capitalize each word except the first one and join back together. However, I'm curious as...
Read more >
Converting an underscored string to camelcase - TeX
I would like to take a string containing underscores and convert it to CamelCase. I am attempting to do this using the stringstrings...
Read more >
Convert Strings into any Case • snakecase
The snakecase package introduces a fresh and straightforward approach on case conversion, based upon a consistent design philosophy. For a short intro regarding ......
Read more >
Convert a String to Camel Case - Baeldung
Camel's case allows us to join multiple words by removing whitespace and using capital letters to show word boundaries. There are two types:....
Read more >
Convert Strings to CamelCase | Python | Codewars - YouTube
Refreshing my python. Leveling up Codewars. String Method in Python.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found