Skip to content

Commit 78731ce

Browse files
macisamuelecortinico
authored andcommitted
Fix model sanitisation (#19)
* Ignore java head-dumps * Define initial test infrastructure * Fix model sanitisation * Update test naming to follow typical JUnit test naming convention
1 parent 3cb93b6 commit 78731ce

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.iml
22
.*
3-
local.properties
4-
venv/
53
build/
4+
java_pid*.hprof
5+
local.properties
66
out/
7+
venv/

plugin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ dependencies {
2020
implementation("com.google.guava:guava:27.0-jre")
2121
implementation("io.swagger:swagger-codegen:2.3.1")
2222
implementation("org.json:json:20180813")
23+
24+
testImplementation("junit:junit:4.12")
2325
}
2426

2527
tasks.register<Jar>("sourcesJar") {

plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class KotlinGenerator : SharedCodegen() {
319319
name
320320
} else {
321321
matchXModel(name)
322-
.split(".").last()
322+
.replace(Regex("(\\.|\\s)"), "_")
323323
.toPascalCase()
324324
.sanitizeKotlinSpecificNames(specialCharReplacements)
325325
.apply { escapeReservedWord(this) }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.yelp.codegen
2+
3+
import org.junit.Test
4+
5+
class KotlinGeneratorTest {
6+
7+
@Test
8+
fun toModelName_doesNotTrimTooMuch() {
9+
assert(KotlinGenerator().toModelName("model") == "Model")
10+
assert(KotlinGenerator().toModelName("model with space") == "ModelWithSpace")
11+
assert(KotlinGenerator().toModelName("model with dot.s") == "ModelWithDotS")
12+
assert(KotlinGenerator().toModelName("model with userscore_s") == "ModelWithUserscoreS")
13+
}
14+
}

0 commit comments

Comments
 (0)