Skip to content

Commit

Permalink
Fix model sanitisation (#19)
Browse files Browse the repository at this point in the history
* Ignore java head-dumps
* Define initial test infrastructure
* Fix model sanitisation
* Update test naming to follow typical JUnit test naming convention
  • Loading branch information
macisamuele authored and cortinico committed Feb 20, 2019
1 parent 3cb93b6 commit 78731ce
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.iml
.*
local.properties
venv/
build/
java_pid*.hprof
local.properties
out/
venv/
2 changes: 2 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dependencies {
implementation("com.google.guava:guava:27.0-jre")
implementation("io.swagger:swagger-codegen:2.3.1")
implementation("org.json:json:20180813")

testImplementation("junit:junit:4.12")
}

tasks.register<Jar>("sourcesJar") {
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class KotlinGenerator : SharedCodegen() {
name
} else {
matchXModel(name)
.split(".").last()
.replace(Regex("(\\.|\\s)"), "_")
.toPascalCase()
.sanitizeKotlinSpecificNames(specialCharReplacements)
.apply { escapeReservedWord(this) }
Expand Down
14 changes: 14 additions & 0 deletions plugin/src/test/java/com/yelp/codegen/KotlinGeneratorTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.yelp.codegen

import org.junit.Test

class KotlinGeneratorTest {

@Test
fun toModelName_doesNotTrimTooMuch() {
assert(KotlinGenerator().toModelName("model") == "Model")
assert(KotlinGenerator().toModelName("model with space") == "ModelWithSpace")
assert(KotlinGenerator().toModelName("model with dot.s") == "ModelWithDotS")
assert(KotlinGenerator().toModelName("model with userscore_s") == "ModelWithUserscoreS")
}
}

0 comments on commit 78731ce

Please sign in to comment.