Bug Report Checklist
Description
The Kotlin code generator is not sanitizing enum values correctly. This occurs for hyphenated values where it gets translated to Minus.
This was previously addressed in Issue #9683 and partially fixed in PR #16267 (since it does not cover enum values). The fix should be quick to address but let me know if you need me to submit a PR for this
openapi-generator version
Version 7.13.0
OpenAPI declaration file content or url
Any OpenAPI file that contains an enum whose value contains an hyphen:
properties:
propertyName:
type: string
default: HYPHENATED-VALUE
enum:
- HYPHENATED-VALUE
Steps to reproduce
- Go to AbstractKotlinCodegenTest.java
- Add an assertion for any enum type. Example:
assertEquals(codegen.toEnumVarName("long-Name", null), "longName");
- Run the test
- Verify that it fails. It should be
longName instead of longMinusName
Related issues/PRs
Similar to Issue #9683 and partially fixed in PR #16267
Suggest a fix
Replace line modified = value; with modified = sanitizeName(value, "\\W-[\\$]"); in AbstractKotlinCodegen.java
Add unit tests for the different enum properties. Example:
- original ->
long-Name becomes longMinusName
- snake_case ->
long-Name becomes long_name
- camelCase ->
long-Name becomes longName
- PascalCase ->
long-Name becomes LongName
- UPPERCASE ->
long-Name becomes LONG_NAME
Bug Report Checklist
Description
The Kotlin code generator is not sanitizing enum values correctly. This occurs for hyphenated values where it gets translated to
Minus.This was previously addressed in Issue #9683 and partially fixed in PR #16267 (since it does not cover enum values). The fix should be quick to address but let me know if you need me to submit a PR for this
openapi-generator version
Version 7.13.0
OpenAPI declaration file content or url
Any OpenAPI file that contains an enum whose value contains an hyphen:
Steps to reproduce
assertEquals(codegen.toEnumVarName("long-Name", null), "longName");longNameinstead oflongMinusNameRelated issues/PRs
Similar to Issue #9683 and partially fixed in PR #16267
Suggest a fix
Replace line
modified = value;withmodified = sanitizeName(value, "\\W-[\\$]");in AbstractKotlinCodegen.javaAdd unit tests for the different enum properties. Example:
long-NamebecomeslongMinusNamelong-Namebecomeslong_namelong-NamebecomeslongNamelong-NamebecomesLongNamelong-NamebecomesLONG_NAME