-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Labels
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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
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-VALUESteps 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
longNameinstead oflongMinusName
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-NamebecomeslongMinusName - snake_case ->
long-Namebecomeslong_name - camelCase ->
long-NamebecomeslongName - PascalCase ->
long-NamebecomesLongName - UPPERCASE ->
long-NamebecomesLONG_NAME
AlessandroBagnoliGabriellCosta