OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.58k stars 6.52k forks source link

[BUG] getters and setters in scala codegen are incorrectly escaped #15884

Open kevinwright opened 1 year ago

kevinwright commented 1 year ago

Bug Report Checklist

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

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L3636-L3641

also used here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L3842

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

wing328 commented 1 year ago

The quickest fix would be to override getterAndSetterCapitalize in AbstractScalaCodegen to not perform escaping

Can you please file a PR with the suggested fix? let me know if you need any help with the PR.