Skip to content

Checking the uniqueness of elements in the ENUM to ensure the correctness of the generated classes #14366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shmakovalexey
Copy link

@shmakovalexey shmakovalexey commented Jan 2, 2023

It's another solution for #893

The project [swagger-codegen] (https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L324) contains a check for the uniqueness of names, as a result, when using multibyte characters, instead of a list of characters "_", classes are obtained without compilation errors. I think we need to do the same.

In a perfect world, it's the swagger description provider that should add the "x-enum-names" parameter, but in the real world it's very hard to get an external organization to modify their file. Thus, it will be very useful if third-party files are converted into classes that compile without errors.

…ness of the generated classes

Signed-off-by: ShmakovAlexey <year2077@gmail.com>
* @return <code>name</code>, uniquely suffixed as necessary.
*/
protected String ensureUniqueName(Map<String, Integer> uniqueNames, String name) {
int count = uniqueNames.containsKey(name) ? uniqueNames.get(name) + 1 : 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor
int count = uniqueNames.getOrDefault(name, 0) + 1;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@wing328
Copy link
Member

wing328 commented Feb 8, 2023

@shmakovalexey thanks for the PR. Let me try to run some tests this weekend.

cc @OpenAPITools/generator-core-team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants