Skip to content

Commit ae66c33

Browse files
authored
[kotlin][client] make base path globally configurable (#5450)
* [kotlin][client] make base path configurable * [kotlin][client] update pet project * [kotlin][client] set default base path * [kotlin][client] set default base path * [kotlin][client] set default base path
1 parent 4c5785d commit ae66c33

File tree

33 files changed

+233
-33
lines changed

33 files changed

+233
-33
lines changed

modules/openapi-generator/src/main/resources/kotlin-client/api.mustache

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import {{packageName}}.infrastructure.Success
1717
import {{packageName}}.infrastructure.toMultiValue
1818

1919
{{#operations}}
20-
{{#nonPublicApi}}internal {{/nonPublicApi}}class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(basePath) {
20+
{{#nonPublicApi}}internal {{/nonPublicApi}}class {{classname}}(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
21+
companion object {
22+
@JvmStatic
23+
val defaultBasePath: String by lazy {
24+
System.getProperties().getProperty("{{packageName}}.baseUrl", "{{{basePath}}}")
25+
}
26+
}
2127

2228
{{#operation}}
2329
/**

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ import retrofit2.converter.moshi.MoshiConverterFactory
1111
{{/moshi}}
1212

1313
{{#nonPublicApi}}internal {{/nonPublicApi}}class ApiClient(
14-
private var baseUrl: String = "{{{basePath}}}",
14+
private var baseUrl: String = defaultBasePath,
1515
private var okHttpClient: OkHttpClient
1616
) {
17+
companion object {
18+
@JvmStatic
19+
val defaultBasePath: String by lazy {
20+
System.getProperties().getProperty("{{packageName}}.baseUrl", "{{{basePath}}}")
21+
}
22+
}
23+
1724
init {
1825
normalizeBaseUrl()
1926
}

samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Create user

samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ import retrofit2.converter.scalars.ScalarsConverterFactory
66
import retrofit2.converter.moshi.MoshiConverterFactory
77

88
class ApiClient(
9-
private var baseUrl: String = "http://petstore.swagger.io/v2",
9+
private var baseUrl: String = defaultBasePath,
1010
private var okHttpClient: OkHttpClient
1111
) {
12+
companion object {
13+
@JvmStatic
14+
val defaultBasePath: String by lazy {
15+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
16+
}
17+
}
18+
1219
init {
1320
normalizeBaseUrl()
1421
}

samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
2626
import org.openapitools.client.infrastructure.Success
2727
import org.openapitools.client.infrastructure.toMultiValue
2828

29-
class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
30+
companion object {
31+
@JvmStatic
32+
val defaultBasePath: String by lazy {
33+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
34+
}
35+
}
3036

3137
/**
3238
* Add a new pet to the store

samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
2525
import org.openapitools.client.infrastructure.Success
2626
import org.openapitools.client.infrastructure.toMultiValue
2727

28-
class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
28+
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
29+
companion object {
30+
@JvmStatic
31+
val defaultBasePath: String by lazy {
32+
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
33+
}
34+
}
2935

3036
/**
3137
* Delete purchase order by ID

0 commit comments

Comments
 (0)