Skip to content

Commit 8ab1cbc

Browse files
PatrickNLTwing328
authored andcommitted
Camelize Kotlin model names and filenames (#8085)
Previously the case of the names could be inconsistent if there were nested object properties. Eg. 'MyNewPet_barking_type' now becomes 'MyNewPetBarkingType'. Ideally, we should use nested classes to take advantage of the namespace of the parent class, but this is much more work.
1 parent 8fa54a9 commit 8ab1cbc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,22 @@ public String toModelName(final String name) {
453453
String modifiedName = name.replaceAll("\\.", "");
454454
modifiedName = sanitizeKotlinSpecificNames(modifiedName);
455455

456+
// Camelize name of nested properties
457+
modifiedName = camelize(modifiedName);
458+
456459
if (reservedWords.contains(modifiedName)) {
457460
modifiedName = escapeReservedWord(modifiedName);
458461
}
459462

460463
return titleCase(modifiedName);
461464
}
462465

466+
@Override
467+
public String toModelFilename(String name) {
468+
// Should be the same as the model name
469+
return toModelName(name);
470+
}
471+
463472
/**
464473
* Provides a strongly typed declaration for simple arrays of some type and arrays of arrays of some type.
465474
*

modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ public static Object[][] modelNames() {
221221
return new Object[][]{
222222
{"TestNs.TestClass", new ModelNameTest("TestNs.TestClass", "TestNsTestClass")},
223223
{"$", new ModelNameTest("$", "Dollar")},
224-
{"for", new ModelNameTest("`for`", "`for`")},
225-
{"One<Two", new ModelNameTest("One<Two", "OneLess_ThanTwo")},
226-
{"this is a test", new ModelNameTest("this is a test", "This_is_a_test")}
224+
{"for", new ModelNameTest("`for`", "For")},
225+
{"One<Two", new ModelNameTest("One<Two", "OneLessThanTwo")},
226+
{"this is a test", new ModelNameTest("this is a test", "ThisIsATest")}
227227
};
228228
}
229229

0 commit comments

Comments
 (0)