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

[kotlin][client] make base path globally configurable #5450

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import {{packageName}}.infrastructure.Success
import {{packageName}}.infrastructure.toMultiValue

{{#operations}}
{{#nonPublicApi}}internal {{/nonPublicApi}}class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(basePath) {
{{#nonPublicApi}}internal {{/nonPublicApi}}class {{classname}}(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("{{packageName}}.baseUrl", "{{{basePath}}}")
}
}

{{#operation}}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import retrofit2.converter.moshi.MoshiConverterFactory
{{/moshi}}

{{#nonPublicApi}}internal {{/nonPublicApi}}class ApiClient(
private var baseUrl: String = "{{{basePath}}}",
private var baseUrl: String = defaultBasePath,
private var okHttpClient: OkHttpClient
) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("{{packageName}}.baseUrl", "{{{basePath}}}")
}
}

init {
normalizeBaseUrl()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
internal class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
internal class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class UserApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import retrofit2.converter.scalars.ScalarsConverterFactory
import retrofit2.converter.moshi.MoshiConverterFactory

class ApiClient(
private var baseUrl: String = "http://petstore.swagger.io/v2",
private var baseUrl: String = defaultBasePath,
private var okHttpClient: OkHttpClient
) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

init {
normalizeBaseUrl()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
class StoreApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty("org.openapitools.client.baseUrl", "http://petstore.swagger.io/v2")
}
}

/**
* Delete purchase order by ID
Expand Down
Loading