mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-06 15:40:54 +00:00
bugfix: issue-4051
This commit is contained in:
parent
14bca6cd89
commit
f57e7c0933
@ -363,6 +363,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(startsWithTwoUppercaseLetters(name)){
|
||||||
|
name = name.substring(0, 2).toLowerCase() + name.substring(2);
|
||||||
|
}
|
||||||
|
|
||||||
// camelize (lower first character) the variable name
|
// camelize (lower first character) the variable name
|
||||||
// pet_id => petId
|
// pet_id => petId
|
||||||
name = camelize(name, true);
|
name = camelize(name, true);
|
||||||
@ -375,6 +379,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
return name;
|
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
|
@Override
|
||||||
public String toParamName(String name) {
|
public String toParamName(String name) {
|
||||||
// to avoid conflicts with 'callback' parameter for async call
|
// to avoid conflicts with 'callback' parameter for async call
|
||||||
@ -935,8 +947,4 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toRegularExpression(String pattern) {
|
|
||||||
return escapeText(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -360,6 +360,32 @@ public class JavaModelTest {
|
|||||||
Assert.assertTrue(property.isNotContainer);
|
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")
|
@Test(description = "convert hyphens per issue 503")
|
||||||
public void hyphensTest() {
|
public void hyphensTest() {
|
||||||
final Model model = new ModelImpl()
|
final Model model = new ModelImpl()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user