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

[Java] Getter/Setter naming convention not followed in generated models (#8282) #9129

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ public String toGetter(String name) {
}

/**
* Output the Getter name, e.g. getSize
* Output the Setter name, e.g. setSize
*
* @param name the name of the property
* @return setter name based on naming convention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,12 @@ public void setSupportJava6(boolean value) {
this.supportJava6 = value;
}

@Override
public String toRegularExpression(String pattern) {
return escapeText(pattern);
}

@Override
public boolean convertPropertyToBoolean(String propertyKey) {
boolean booleanValue = false;
if (additionalProperties.containsKey(propertyKey)) {
Expand All @@ -1313,6 +1315,7 @@ public boolean convertPropertyToBoolean(String propertyKey) {
return booleanValue;
}

@Override
public void writePropertyBack(String propertyKey, boolean value) {
additionalProperties.put(propertyKey, value);
}
Expand All @@ -1323,10 +1326,31 @@ public void writePropertyBack(String propertyKey, boolean value) {
* @param name the name of the property
* @return partial getter name based on naming convention
*/
@Override
public String toBooleanGetter(String name) {
return getterAndSetterCapitalize(name);
}

/**
* Camelize the method name of the getter and setter for Java
* Except when the second letter of the field name is already uppercase
* Refer to section 8.8: Capitalization of inferred names of the JavaBeans API specification
* http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf)
*
* @param name string to be camelized
* @return Camelized string
*/
@Override
public String getterAndSetterCapitalize(String name) {
if (name == null || name.length() == 0) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1))){
return name;
}
return camelize(toVarName(name));
}

@Override
public String sanitizeTag(String tag) {
tag = camelize(underscore(sanitizeName(tag)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#pattern}}@Pattern(regexp="{{{pattern}}}") {{/pattern}}{{!
{{#pattern}}@Pattern(regexp="{{{pattern}}}"{{#vendorExtensions.x-pattern-message}}, message="{{vendorExtensions.x-pattern-message}}"{{/vendorExtensions.x-pattern-message}}) {{/pattern}}{{!
minLength && maxLength set
}}{{#minLength}}{{#maxLength}}@Size(min={{minLength}},max={{maxLength}}) {{/maxLength}}{{/minLength}}{{!
minLength set, maxLength not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ public void secondCharUpperCaseNamesTest() {

final CodegenProperty property = cm.vars.get(0);
Assert.assertEquals(property.baseName, "pId");
Assert.assertEquals(property.getter, "getPId");
Assert.assertEquals(property.setter, "setPId");
Assert.assertEquals(property.getter, "getpId");
Assert.assertEquals(property.setter, "setpId");
Assert.assertEquals(property.datatype, "String");
Assert.assertEquals(property.name, "pId");
Assert.assertEquals(property.defaultValue, "null");
Expand All @@ -413,8 +413,8 @@ public void firstTwoUpperCaseLetterNamesTest() {

final CodegenProperty property = cm.vars.get(0);
Assert.assertEquals(property.baseName, "ATTName");
Assert.assertEquals(property.getter, "getAtTName");
Assert.assertEquals(property.setter, "setAtTName");
Assert.assertEquals(property.getter, "getATTName");
Assert.assertEquals(property.setter, "setATTName");
Assert.assertEquals(property.datatype, "String");
Assert.assertEquals(property.name, "atTName");
Assert.assertEquals(property.defaultValue, "null");
Expand Down