Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix model sanitisation #19

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}