diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/api_doc.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/api_doc.mustache index a997cafd1621..d8dcd68632cc 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/api_doc.mustache @@ -68,18 +68,42 @@ Configure {{name}}: {{/isApiKey}} {{#isBasic}} {{#isBasicBasic}} -Configure {{name}}: - ApiClient.username = "" - ApiClient.password = "" +Configure {{name}} statically: +```kotlin +ApiClient.username = "" +ApiClient.password = "" +``` +{{#jvm-okhttp}} +Configure {{name}} dynamically: +```kotlin +apiInstance.userCredentialProvider = { "user" to "pass" } +``` +{{/jvm-okhttp}} {{/isBasicBasic}} {{#isBasicBearer}} -Configure {{name}}: - ApiClient.accessToken = "" +Configure {{name}} statically: +```kotlin +ApiClient.accessToken = "" +``` +{{#jvm-okhttp}} +Configure {{name}} dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` +{{/jvm-okhttp}} {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} -Configure {{name}}: - ApiClient.accessToken = "" +Configure {{name}} statically: +```kotlin +ApiClient.accessToken = "" +``` +{{#jvm-okhttp}} +Configure {{name}} dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` +{{/jvm-okhttp}} {{/isOAuth}} {{/authMethods}} @@ -89,4 +113,4 @@ Configure {{name}}: - **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}} {{/operation}} -{{/operations}} \ No newline at end of file +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index 3dd83f71487a..c657675bb99c 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -148,6 +148,9 @@ import com.squareup.moshi.adapter {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var userCredentialsProvider: () -> Pair = { username to password } + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -460,25 +463,26 @@ import com.squareup.moshi.adapter {{#isBasic}} {{#isBasicBasic}} if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - username?.let { username -> - password?.let { password -> - requestConfig.headers[AUTHORIZATION] = okhttp3.Credentials.basic(username, password) + val (user, passw) = userCredentialsProvider() + user?.let { user -> + passw?.let { passw -> + requestConfig.headers[AUTHORIZATION] = okhttp3.Credentials.basic(user, passw) } } } {{/isBasicBasic}} {{#isBasicBearer}} if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken" + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token" } } {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } {{/isOAuth}} diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/docs/AuthApi.md b/samples/client/echo_api/kotlin-jvm-okhttp/docs/AuthApi.md index 2614b18e353a..df299d51a1a2 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/docs/AuthApi.md +++ b/samples/client/echo_api/kotlin-jvm-okhttp/docs/AuthApi.md @@ -45,9 +45,15 @@ This endpoint does not need any parameter. ### Authorization -Configure http_auth: - ApiClient.username = "" - ApiClient.password = "" +Configure http_auth statically: +```kotlin +ApiClient.username = "" +ApiClient.password = "" +``` +Configure http_auth dynamically: +```kotlin +apiInstance.userCredentialProvider = { "user" to "pass" } +``` ### HTTP request headers @@ -91,8 +97,14 @@ This endpoint does not need any parameter. ### Authorization -Configure http_bearer_auth: - ApiClient.accessToken = "" +Configure http_bearer_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure http_bearer_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 75def196d6e1..d678c810e35f 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,15 +360,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - username?.let { username -> - password?.let { password -> - requestConfig.headers[AUTHORIZATION] = okhttp3.Credentials.basic(username, password) + val (user, passw) = userCredentialsProvider() + user?.let { user -> + passw?.let { passw -> + requestConfig.headers[AUTHORIZATION] = okhttp3.Credentials.basic(user, passw) } } } if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken" + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token" } } } diff --git a/samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/AuthApi.md b/samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/AuthApi.md index 2614b18e353a..185917cb7c25 100644 --- a/samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/AuthApi.md +++ b/samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/AuthApi.md @@ -45,9 +45,11 @@ This endpoint does not need any parameter. ### Authorization -Configure http_auth: - ApiClient.username = "" - ApiClient.password = "" +Configure http_auth statically: +```kotlin +ApiClient.username = "" +ApiClient.password = "" +``` ### HTTP request headers @@ -91,8 +93,10 @@ This endpoint does not need any parameter. ### Authorization -Configure http_bearer_auth: - ApiClient.accessToken = "" +Configure http_bearer_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/AuthApi.md b/samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/AuthApi.md index 2614b18e353a..185917cb7c25 100644 --- a/samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/AuthApi.md +++ b/samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/AuthApi.md @@ -45,9 +45,11 @@ This endpoint does not need any parameter. ### Authorization -Configure http_auth: - ApiClient.username = "" - ApiClient.password = "" +Configure http_auth statically: +```kotlin +ApiClient.username = "" +ApiClient.password = "" +``` ### HTTP request headers @@ -91,8 +93,10 @@ This endpoint does not need any parameter. ### Authorization -Configure http_bearer_auth: - ApiClient.accessToken = "" +Configure http_bearer_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/docs/PetApi.md b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/docs/PetApi.md index e0bf879c9a65..38e8d3e890a5 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/docs/PetApi.md +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/docs/PetApi.md @@ -54,8 +54,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -103,8 +109,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -151,8 +163,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -199,8 +217,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -296,8 +320,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -347,8 +377,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -399,8 +435,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 6ce203cc15e2..5debecf8c25b 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/docs/StuffApi.md b/samples/client/others/kotlin-jvm-okhttp-path-comments/docs/StuffApi.md index 5208c69e8d44..777d2a049b31 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/docs/StuffApi.md +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/docs/StuffApi.md @@ -44,8 +44,14 @@ This endpoint does not need any parameter. ### Authorization -Configure bearerAuth: - ApiClient.accessToken = "" +Configure bearerAuth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure bearerAuth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9c0e379663b8..93bef21acd1a 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken" + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token" } } } diff --git a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5ae765ef16bd..b28f0b001886 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -120,6 +120,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-array-nullable-items/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-nullable-items/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-array-nullable-items/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-nullable-items/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-explicit/docs/PetApi.md b/samples/client/petstore/kotlin-explicit/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-explicit/docs/PetApi.md +++ b/samples/client/petstore/kotlin-explicit/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8dde76474b55..b77ffdbfb22e 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. public val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + public var userCredentialsProvider: () -> Pair = { username to password } + public var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-gson/docs/PetApi.md b/samples/client/petstore/kotlin-gson/docs/PetApi.md index e0bf879c9a65..38e8d3e890a5 100644 --- a/samples/client/petstore/kotlin-gson/docs/PetApi.md +++ b/samples/client/petstore/kotlin-gson/docs/PetApi.md @@ -54,8 +54,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -103,8 +109,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -151,8 +163,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -199,8 +217,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -296,8 +320,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -347,8 +377,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -399,8 +435,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index d6f907f7947c..0be2f0b3bd69 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -356,8 +359,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-jackson/docs/PetApi.md b/samples/client/petstore/kotlin-jackson/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-jackson/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jackson/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 18912784874d..2abbb30eb798 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -356,8 +359,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-json-request-string/docs/PetApi.md b/samples/client/petstore/kotlin-json-request-string/docs/PetApi.md index 318ca7c9e1e9..3bebda4ecd49 100644 --- a/samples/client/petstore/kotlin-json-request-string/docs/PetApi.md +++ b/samples/client/petstore/kotlin-json-request-string/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -192,8 +210,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -286,8 +310,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -335,8 +365,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -385,8 +421,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 44ee00b60b08..c4289daa1493 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -121,6 +121,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -364,8 +367,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-jvm-ktor-gson/docs/FakeApi.md b/samples/client/petstore/kotlin-jvm-ktor-gson/docs/FakeApi.md index 5d6e47a6f2b3..c3412b1b0015 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-gson/docs/FakeApi.md +++ b/samples/client/petstore/kotlin-jvm-ktor-gson/docs/FakeApi.md @@ -96,8 +96,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-ktor-gson/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-ktor-gson/docs/PetApi.md index 0a13a8fa8ce3..b75318d1bc72 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-gson/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-ktor-gson/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-ktor-jackson/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-ktor-jackson/docs/PetApi.md index 0b928e328e60..bf941538de6c 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-jackson/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-ktor-jackson/docs/PetApi.md @@ -51,8 +51,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -98,8 +100,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -146,8 +150,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -194,8 +200,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -288,8 +296,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -337,8 +347,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -387,8 +399,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/docs/PetApi.md index 0a13a8fa8ce3..b75318d1bc72 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f4b11927a365..9ec489f5ae54 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -122,6 +122,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -359,8 +362,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-jvm-spring-2-webclient/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-spring-2-webclient/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-spring-2-webclient/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-spring-2-webclient/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-spring-3-restclient/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-spring-3-restclient/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-spring-3-restclient/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-spring-3-restclient/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-spring-3-webclient/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-spring-3-webclient/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-spring-3-webclient/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-spring-3-webclient/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-vertx-gson/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-vertx-gson/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-gson/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-vertx-gson/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-vertx-jackson/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-jvm-vertx-moshi/docs/PetApi.md b/samples/client/petstore/kotlin-jvm-vertx-moshi/docs/PetApi.md index 9eb15f0e7013..c185d4179761 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-moshi/docs/PetApi.md +++ b/samples/client/petstore/kotlin-jvm-vertx-moshi/docs/PetApi.md @@ -54,8 +54,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -103,8 +105,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -151,8 +155,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -199,8 +205,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -296,8 +304,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -347,8 +357,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -399,8 +411,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/docs/PetApi.md b/samples/client/petstore/kotlin-kotlinx-datetime/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/docs/PetApi.md +++ b/samples/client/petstore/kotlin-kotlinx-datetime/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3f8f02e86937..55f11cac9d72 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-modelMutable/docs/PetApi.md b/samples/client/petstore/kotlin-modelMutable/docs/PetApi.md index e385754514fb..1867aec4a0bc 100644 --- a/samples/client/petstore/kotlin-modelMutable/docs/PetApi.md +++ b/samples/client/petstore/kotlin-modelMutable/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3f8f02e86937..55f11cac9d72 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-moshi-codegen/docs/PetApi.md b/samples/client/petstore/kotlin-moshi-codegen/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/docs/PetApi.md +++ b/samples/client/petstore/kotlin-moshi-codegen/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3f8f02e86937..55f11cac9d72 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-multiplatform-kotlinx-datetime/docs/PetApi.md b/samples/client/petstore/kotlin-multiplatform-kotlinx-datetime/docs/PetApi.md index 0b928e328e60..bf941538de6c 100644 --- a/samples/client/petstore/kotlin-multiplatform-kotlinx-datetime/docs/PetApi.md +++ b/samples/client/petstore/kotlin-multiplatform-kotlinx-datetime/docs/PetApi.md @@ -51,8 +51,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -98,8 +100,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -146,8 +150,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -194,8 +200,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -288,8 +296,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -337,8 +347,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -387,8 +399,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-multiplatform/docs/PetApi.md b/samples/client/petstore/kotlin-multiplatform/docs/PetApi.md index 0b928e328e60..bf941538de6c 100644 --- a/samples/client/petstore/kotlin-multiplatform/docs/PetApi.md +++ b/samples/client/petstore/kotlin-multiplatform/docs/PetApi.md @@ -51,8 +51,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -98,8 +100,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -146,8 +150,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -194,8 +200,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -288,8 +296,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -337,8 +347,10 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers @@ -387,8 +399,10 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0197390a824a..88bc9ba0a7e3 100644 --- a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin-nonpublic/docs/PetApi.md b/samples/client/petstore/kotlin-nonpublic/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-nonpublic/docs/PetApi.md +++ b/samples/client/petstore/kotlin-nonpublic/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index aff54eb43a1b..eb0c4fa8d3f0 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-nullable/docs/PetApi.md b/samples/client/petstore/kotlin-nullable/docs/PetApi.md index c34fce5f4a46..5ca7d71d8184 100644 --- a/samples/client/petstore/kotlin-nullable/docs/PetApi.md +++ b/samples/client/petstore/kotlin-nullable/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3f8f02e86937..55f11cac9d72 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-string/docs/PetApi.md b/samples/client/petstore/kotlin-string/docs/PetApi.md index ea42a0d82f60..2fd292cbf9e0 100644 --- a/samples/client/petstore/kotlin-string/docs/PetApi.md +++ b/samples/client/petstore/kotlin-string/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3f8f02e86937..55f11cac9d72 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-threetenbp/docs/PetApi.md b/samples/client/petstore/kotlin-threetenbp/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin-threetenbp/docs/PetApi.md +++ b/samples/client/petstore/kotlin-threetenbp/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8f316e316b2e..ef9cb9e15418 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5ae765ef16bd..b28f0b001886 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -120,6 +120,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * diff --git a/samples/client/petstore/kotlin/docs/PetApi.md b/samples/client/petstore/kotlin/docs/PetApi.md index 6856ea516dab..630fc891638b 100644 --- a/samples/client/petstore/kotlin/docs/PetApi.md +++ b/samples/client/petstore/kotlin/docs/PetApi.md @@ -51,8 +51,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -98,8 +104,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -146,8 +158,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -194,8 +212,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -288,8 +312,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -337,8 +367,14 @@ null (empty response body) ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers @@ -387,8 +423,14 @@ try { ### Authorization -Configure petstore_auth: - ApiClient.accessToken = "" +Configure petstore_auth statically: +```kotlin +ApiClient.accessToken = "" +``` +Configure petstore_auth dynamically: +```kotlin +apiInstance.accessTokenProvider = { "" } +``` ### HTTP request headers diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3f8f02e86937..55f11cac9d72 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -119,6 +119,9 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val builder: OkHttpClient.Builder = OkHttpClient.Builder() } + var userCredentialsProvider: () -> Pair = { username to password } + var accessTokenProvider: () -> String? = { accessToken } + /** * Guess Content-Type header from the given byteArray (defaults to "application/octet-stream"). * @@ -357,8 +360,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { - accessToken?.let { accessToken -> - requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " + accessTokenProvider()?.let { token -> + requestConfig.headers[AUTHORIZATION] = "Bearer $token " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) {