Skip to content

Commit 1e32c7e

Browse files
committed
Remove leading slash if Swagger Spec are specifying a basePath
When generating Retrofit interfaces, we need to remove the leading slash from the generated path. Having a leading slash will force the path to be absolute for the host and will make URLs like: https://petstore.swagger.io/v2/ impossible to call. Fixes #49
1 parent a3da180 commit 1e32c7e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class KotlinGenerator : SharedCodegen() {
3333

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

3738
private val retrofitImport = mapOf(
3839
"GET" to "retrofit2.http.GET",
@@ -407,6 +408,11 @@ class KotlinGenerator : SharedCodegen() {
407408
getHeadersToIgnore().forEach { headerName ->
408409
ignoreHeaderParameter(headerName, codegenOperation)
409410
}
411+
412+
// Let's remove the leading
413+
if (!basePath.isNullOrBlank()) {
414+
codegenOperation.path = codegenOperation.path.removePrefix("/")
415+
}
410416
return codegenOperation
411417
}
412418

@@ -432,6 +438,7 @@ class KotlinGenerator : SharedCodegen() {
432438

433439
// Override the swagger version with the one provided from command line.
434440
swagger.info.version = additionalProperties[SPEC_VERSION] as String
441+
this.basePath = swagger.basePath
435442
}
436443

437444
/**

0 commit comments

Comments
 (0)