OpenAPITools / OpenAPITools/openapi-generator

Unicode chars are ignored as enum values

Open
#9,411 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Generating java code from spec with enums using non-latin (russian-cyrillic) chars gives invalid output. For example for enum like:

"enum" : ["один", "два", "три"] ...

output (for java) looks like:

public enum ... {
  _("один"),
  _("два"),
  _("три")
 ...
}

Which gives compile error. Since java supports unicode chars for enum names - corresponding code should be replaced with one which will not trim non-latin chars.

https://github.com/OpenAPITools/openapi-generator/blob/8f5639554e96a9beaf0b4c87b9dac52afcc1ef83/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java#L1406

Proposal: replace regexp with Unicode-enabled one

String var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT);

with

String var = value.replaceAll("(?U)\\W+", "_").toUpperCase(Locale.ROOT);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java at the enum-name handling around line 1406. Generate Java code from a spec containing Cyrillic enum values and verify the generated enum constants preserve those characters and compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.