OpenAPITools / OpenAPITools/openapi-generator
[BUG] getters and setters in scala codegen are incorrectly escaped
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?
Description
For a member that's a reserved word, several properties passed to the mustache template contain backticks.
for example, properties from debugModels:
{
"baseName" : "type",
"getter" : "get`Type`",
"setter" : "set`Type`",
"name" : "`type`",
"defaultValueWithParam" : " = data.type;",
...,
}
openapi-generator version
Master
Generation Details
This occurs using any of the scala-based generators where the model contains a keyword
Steps to reproduce
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/12226
Which incorrectly tags this as specific to just scala-sttp and enums
Suggest a fix
The properties getter, setter, nameInCamelCase and nameInSnakeCase should be based on the unquoted form of the member name.
The root problem is that DefaultCodegen uses toVarName
But that happens after escaping:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java#L291
The quickest fix would be to override getterAndSetterCapitalize in AbstractScalaCodegen to not perform escaping
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
Read DefaultCodegen.java at the referenced toVarName usages and AbstractScalaCodegen.java around getterAndSetterCapitalize. Reproduce generation for a Scala model containing a keyword, then verify that getter, setter, nameInCamelCase, and nameInSnakeCase use unquoted member names across the Scala-based generators.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, scala
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100