OpenAPITools / OpenAPITools/openapi-generator
[REQ] Normalize accented characters in names
Nobody has claimed this yet.
- 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
stripAccentsconfiguration (which defaults tofalse) to replace accented characters with their "standard" letters; or - Create another option to combine with
allowUnicodeIdentifiers, which would allow three different settings:- "do nothing" (default);
- "allow Unicode identifiers as they are" (current behavior with
allowUnicodeIdentifiers); and - "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
Normalizerclass, but I got better results withStringUtils.stripAccents()
Additional context
n/a
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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