Skip to content

Commit 4491f6c

Browse files
committed
Adding JUnit tests for basePath
1 parent 1e32c7e commit 4491f6c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class KotlinGenerator : SharedCodegen() {
3333

3434
private val apiDocPath = "docs/"
3535
private val modelDocPath = "docs/"
36-
private var basePath: String? = null
36+
internal var basePath: String? = null
3737

3838
private val retrofitImport = mapOf(
3939
"GET" to "retrofit2.http.GET",

plugin/src/test/java/com/yelp/codegen/KotlinGeneratorTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.yelp.codegen
33
import io.swagger.codegen.CodegenModel
44
import io.swagger.codegen.CodegenProperty
55
import io.swagger.models.Info
6+
import io.swagger.models.Operation
67
import io.swagger.models.Swagger
78
import org.junit.Assert.assertEquals
89
import org.junit.Assert.assertFalse
@@ -314,6 +315,30 @@ class KotlinGeneratorTest {
314315
assertEquals("typeKey", KotlinGenerator().removeNonNameElementToCamelCase("[type]key"))
315316
}
316317

318+
@Test
319+
fun fromOperation_withBasePath_removeLeadingSlash() {
320+
val generator = KotlinGenerator()
321+
generator.basePath = "/v2"
322+
val operation = Operation()
323+
val swagger = Swagger()
324+
325+
val codegenOperation = generator.fromOperation("/helloworld", "GET", operation, mutableMapOf(), swagger)
326+
327+
assertEquals("helloworld", codegenOperation.path)
328+
}
329+
330+
@Test
331+
fun fromOperation_withNoBasePath_leadingSlashIsNotRemoved() {
332+
val generator = KotlinGenerator()
333+
generator.basePath = null
334+
val operation = Operation()
335+
val swagger = Swagger()
336+
337+
val codegenOperation = generator.fromOperation("/helloworld", "GET", operation, mutableMapOf(), swagger)
338+
339+
assertEquals("/helloworld", codegenOperation.path)
340+
}
341+
317342
@Test
318343
fun preprocessSwagger() {
319344
val generator = KotlinGenerator()
@@ -322,8 +347,10 @@ class KotlinGeneratorTest {
322347
val swagger = Swagger()
323348
swagger.info = Info()
324349
swagger.info.version = "1.0.0"
350+
swagger.basePath = "/v2"
325351
generator.preprocessSwagger(swagger)
326352

327353
assertEquals("42.0.0", swagger.info.version)
354+
assertEquals("/v2", generator.basePath)
328355
}
329356
}

0 commit comments

Comments
 (0)