mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-17 21:09:11 +00:00
[Java] Getter/Setter naming convention not followed in generated models (#2095)
fix the getter/setter when the second letter of the field name is already uppercase (following the JavaBeans API specification)
This commit is contained in:
committed by
William Cheng
parent
ad8aa7dc0e
commit
594af33fb8
@@ -1551,7 +1551,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -1378,10 +1378,12 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
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)) {
|
||||
@@ -1391,6 +1393,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePropertyBack(String propertyKey, boolean value) {
|
||||
additionalProperties.put(propertyKey, value);
|
||||
}
|
||||
@@ -1416,6 +1419,33 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Camelize the method name of the getter and setter
|
||||
*
|
||||
* @param name string to be camelized
|
||||
* @return Camelized string
|
||||
*/
|
||||
@Override
|
||||
public String getterAndSetterCapitalize(String name) {
|
||||
boolean lowercaseFirstLetter = false;
|
||||
if (name == null || name.length() == 0) {
|
||||
return name;
|
||||
}
|
||||
name = toVarName(name);
|
||||
//
|
||||
// Let the property name capitalized
|
||||
// except when the first letter of the property name is lowercase and the second letter is 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)
|
||||
//
|
||||
if (name.length() > 1 && Character.isLowerCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) {
|
||||
lowercaseFirstLetter = true;
|
||||
}
|
||||
return camelize(name, lowercaseFirstLetter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
|
||||
Reference in New Issue
Block a user