Skip to content
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

Improve unique class naming strategy by appending an incrementing number instead of adding more and more underscores #476

Merged

Conversation

SergioModulusData
Copy link
Contributor

Problem

If a class already exists with the same name when generating we add a underscore to the name '_'. Using a weirdly formatted jsonSchema, adp, I hit a limitation from the OS on the name length.

Attempted solution

Using a number with two underscore '__' instead of adding underscore to the class name when the class already exists. If the class already ends with a number and has two underscore we search for the number and add a number.

I did the modification to work with ADP crazy repeating schema. Could be useful for others.

Using a number with two underscore '__' instead of adding underscore to the class name when the class already exists.
@joelittlejohn
Copy link
Owner

I like this.

It's quite a major change to the generated types (for some projects) but I think it's a good one. I think we should include this and bump to 0.5.0.

…eClassName

Conflicts:
	jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java
@thachhoang
Copy link
Collaborator

@joelittlejohn should we include this in 1.0.0-alpha2?

@joelittlejohn joelittlejohn added this to the 1.0.0-alpha2 milestone Feb 3, 2018
public static String makeUnique(String className) {
String returnClassName = className;
// Last character is a digit and there is 2 underscore in the className
if (Character.isDigit(className.charAt(className.length() - 1)) && StringUtils.contains(className, "__")) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this check is a little too flexible. I think we should replace this with a regex like .+\_\_(\d+)$, and use the capture group to pull out the current number.

@joelittlejohn joelittlejohn merged commit 2c628d1 into joelittlejohn:master Feb 4, 2018
@joelittlejohn joelittlejohn changed the title Unique class name strategy Improve unique class naming strategy by appending an incrementing number instead of adding more and more underscores Feb 4, 2018
joelittlejohn added a commit that referenced this pull request Feb 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants