OpenAPITools / OpenAPITools/openapi-generator

[REQ] Normalize accented characters in names

Open
#19,783 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Context

The sanitizeName method removes all accented characters from the output, resulting in files with missing letters.

For example, a (Portuguese) tag named "Catálogo - Coleções" (which translates to "Catalog Collections") becomes CatlogoColees, which is very hard to read because of the missing letters.

When using allowUnicodeIdentifiers, the same tag becomes CatálogoColeções, which is valid, but is kind of weird to have files (and classes) named that way.

Describe the solution you'd like

  • Add a stripAccents configuration (which defaults to false) to replace accented characters with their "standard" letters; or
  • Create another option to combine with allowUnicodeIdentifiers, which would allow three different settings:
    1. "do nothing" (default);
    2. "allow Unicode identifiers as they are" (current behavior with allowUnicodeIdentifiers); and
    3. "strip accents" (new behavior).

My suggestion is to use StringUtils.stripAccents() before actually sanitizing the name in DefaultCodegen::sanitizeName().

-        SanitizeNameOptions opts = new SanitizeNameOptions(name, removeCharRegEx, exceptionList);
+        SanitizeNameOptions opts = new SanitizeNameOptions(
+                (stripAccents) ? StringUtils.stripAccents(name) : name,
+                removeCharRegEx,
+                exceptionList
+        );

This way, that same tag "Catálogo - Coleções" would now become CatalogoColecoes, which is may more readable.

I already have implemented this locally and it's working fine. I'm just waiting for any other suggestions before opening the PR, but you can see the actual work in https://github.com/vcampitelli/openapi-generator/pull/1.

Describe alternatives you've considered

  • Remove accented characters from the spec file itself is not an option, as they are part of the language
  • I also tried using the Normalizer class, but I got better results with StringUtils.stripAccents()

Additional context

n/a

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 with modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java and its sanitizeName method, then review the proposed StringUtils.stripAccents() approach and the two configuration alternatives. Done means the selected behavior is configurable and the example name "Catálogo - Coleções" produces the expected readable identifier.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.