bugfix: issue-4051

This commit is contained in:
schnabel 2016-10-25 20:09:24 +02:00
parent 14bca6cd89
commit f57e7c0933
2 changed files with 38 additions and 4 deletions

View File

@ -363,6 +363,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
return name;
}
if(startsWithTwoUppercaseLetters(name)){
name = name.substring(0, 2).toLowerCase() + name.substring(2);
}
// camelize (lower first character) the variable name
// pet_id => petId
name = camelize(name, true);
@ -375,6 +379,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
return name;
}
private boolean startsWithTwoUppercaseLetters(String name) {
boolean startsWithTwoUppercaseLetters = false;
if(name.length() > 1) {
startsWithTwoUppercaseLetters = name.substring(0, 2).equals(name.substring(0, 2).toUpperCase());
}
return startsWithTwoUppercaseLetters;
}
@Override
public String toParamName(String name) {
// to avoid conflicts with 'callback' parameter for async call
@ -935,8 +947,4 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
return sb.toString();
}
public String toRegularExpression(String pattern) {
return escapeText(pattern);
}
}

View File

@ -360,6 +360,32 @@ public class JavaModelTest {
Assert.assertTrue(property.isNotContainer);
}
@Test(description = "convert a model starting with two upper-case letter property names")
public void firstTwoUpperCaseLetterNamesTest() {
final Model model = new ModelImpl()
.description("a model with a property name starting with two upper-case letters")
.property("ATTName", new StringProperty())
.required("ATTName");
final DefaultCodegen codegen = new JavaClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.vars.size(), 1);
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.datatype, "String");
Assert.assertEquals(property.name, "atTName");
Assert.assertEquals(property.defaultValue, "null");
Assert.assertEquals(property.baseType, "String");
Assert.assertNull(property.hasMore);
Assert.assertTrue(property.required);
Assert.assertTrue(property.isNotContainer);
}
@Test(description = "convert hyphens per issue 503")
public void hyphensTest() {
final Model model = new ModelImpl()