forked from loafle/openapi-generator-original
Merge branch 'issue-4051' of https://github.com/schnabel/swagger-codegen into schnabel-issue-4051
This commit is contained in:
commit
66ebdf3e3d
@ -371,6 +371,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);
|
||||
@ -383,6 +387,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
|
||||
@ -942,11 +954,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void setSupportJava6(boolean value) {
|
||||
this.supportJava6 = value;
|
||||
}
|
||||
|
||||
|
||||
public String toRegularExpression(String pattern) {
|
||||
return escapeText(pattern);
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user