@@ -3,6 +3,7 @@ package com.yelp.codegen
33import io.swagger.codegen.CodegenModel
44import io.swagger.codegen.CodegenProperty
55import io.swagger.models.Info
6+ import io.swagger.models.Operation
67import io.swagger.models.Swagger
78import org.junit.Assert.assertEquals
89import 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