Skip to content

[BUG] Generated enum constants have triple underscore when original contains ' - ' #21804

@gertjanschouten

Description

@gertjanschouten

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

After this fix: #21459, when the original string contains a hyphen, surrounded by spaces, the generated enum constant now has three underscores:

"This - string" becomes "THIS___STRING"

Suggested fix: In this file:

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

Replace

modified = value.replaceAll("-", "_");

with:

modified = value.replaceAll(" - ", "_");
modified = value.replaceAll("-", "_");

It could also be that it needs to be fixed on a more fundamental level, because otherwise, there will probably be other edge cases as well.

openapi-generator version

7.15.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions