forked from loafle/openapi-generator-original
[kotlin][KTOR] remove unnecessary dependencies (#13640)
* [kotlin][ktor] add set JSON as the ContentType header for ktor projects samples revert content type * update samples * fix multi-platform sample * revert docs * update samples and fix missing import on multiplatfrom * add missing sample
This commit is contained in:
parent
05f3b00f04
commit
3f4e3afab2
@ -20,8 +20,8 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||
## Requires
|
||||
|
||||
{{#jvm}}
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
{{/jvm}}
|
||||
{{#multiplatform}}
|
||||
* Kotlin 1.5.10
|
||||
|
@ -11,7 +11,7 @@ wrapper {
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.6.10'
|
||||
{{#jvm-ktor}}
|
||||
ext.ktor_version = '2.0.3'
|
||||
ext.ktor_version = '2.1.2'
|
||||
{{/jvm-ktor}}
|
||||
{{#jvm-retrofit2}}
|
||||
ext.retrofitVersion = '2.9.0'
|
||||
|
@ -12,6 +12,7 @@ import io.ktor.client.request.parameter
|
||||
import io.ktor.client.request.request
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.http.contentType
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.Parameters
|
||||
@ -34,11 +35,6 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.fasterxml.jackson.core.util.DefaultIndenter
|
||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
|
||||
{{/jackson}}
|
||||
import org.openapitools.client.auth.ApiKeyAuth
|
||||
import org.openapitools.client.auth.Authentication
|
||||
import org.openapitools.client.auth.HttpBasicAuth
|
||||
import org.openapitools.client.auth.HttpBearerAuth
|
||||
import org.openapitools.client.auth.OAuth
|
||||
import {{packageName}}.auth.*
|
||||
|
||||
{{#nonPublicApi}}internal {{/nonPublicApi}}open class ApiClient(
|
||||
@ -111,7 +107,7 @@ import {{packageName}}.auth.*
|
||||
* @param username Username
|
||||
*/
|
||||
fun setUsername(username: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
?: throw Exception("No HTTP basic authentication configured")
|
||||
auth.username = username
|
||||
}
|
||||
@ -122,7 +118,7 @@ import {{packageName}}.auth.*
|
||||
* @param password Password
|
||||
*/
|
||||
fun setPassword(password: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
?: throw Exception("No HTTP basic authentication configured")
|
||||
auth.password = password
|
||||
}
|
||||
@ -134,7 +130,7 @@ import {{packageName}}.auth.*
|
||||
* @param paramName The name of the API key parameter, or null or set the first key.
|
||||
*/
|
||||
fun setApiKey(apiKey: String, paramName: String? = null) {
|
||||
val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth?
|
||||
?: throw Exception("No API key authentication configured")
|
||||
auth.apiKey = apiKey
|
||||
}
|
||||
@ -146,7 +142,7 @@ import {{packageName}}.auth.*
|
||||
* @param paramName The name of the API key parameter, or null or set the first key.
|
||||
*/
|
||||
fun setApiKeyPrefix(apiKeyPrefix: String, paramName: String? = null) {
|
||||
val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth?
|
||||
?: throw Exception("No API key authentication configured")
|
||||
auth.apiKeyPrefix = apiKeyPrefix
|
||||
}
|
||||
@ -157,7 +153,7 @@ import {{packageName}}.auth.*
|
||||
* @param accessToken Access token
|
||||
*/
|
||||
fun setAccessToken(accessToken: String) {
|
||||
val auth = authentications.values.firstOrNull { it is OAuth } as OAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is OAuth } as OAuth?
|
||||
?: throw Exception("No OAuth2 authentication configured")
|
||||
auth.accessToken = accessToken
|
||||
}
|
||||
@ -168,7 +164,7 @@ import {{packageName}}.auth.*
|
||||
* @param bearerToken The bearer token.
|
||||
*/
|
||||
fun setBearerToken(bearerToken: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth?
|
||||
?: throw Exception("No Bearer authentication configured")
|
||||
auth.bearerToken = bearerToken
|
||||
}
|
||||
@ -199,8 +195,9 @@ import {{packageName}}.auth.*
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
setBody(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,13 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.FormDataContent
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.PartData
|
||||
import kotlin.Unit
|
||||
@ -153,9 +153,9 @@ import {{packageName}}.auth.*
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
this.setBody(body)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@ For more information, please visit [https://example.org](https://example.org)
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -4,13 +4,13 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.FormDataContent
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.PartData
|
||||
import kotlin.Unit
|
||||
@ -142,9 +142,9 @@ open class ApiClient(
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
this.setBody(body)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,13 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.FormDataContent
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.PartData
|
||||
import kotlin.Unit
|
||||
@ -142,9 +142,9 @@ open class ApiClient(
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
this.setBody(body)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -4,13 +4,13 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.FormDataContent
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.PartData
|
||||
import kotlin.Unit
|
||||
@ -142,9 +142,9 @@ open class ApiClient(
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
this.setBody(body)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -8,7 +8,7 @@ wrapper {
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.6.10'
|
||||
ext.ktor_version = '2.0.3'
|
||||
ext.ktor_version = '2.1.2'
|
||||
|
||||
repositories {
|
||||
maven { url "https://repo1.maven.org/maven2" }
|
||||
|
@ -12,6 +12,7 @@ import io.ktor.client.request.parameter
|
||||
import io.ktor.client.request.request
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.http.contentType
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.Parameters
|
||||
@ -23,11 +24,6 @@ import io.ktor.http.takeFrom
|
||||
import io.ktor.serialization.gson.*
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.text.DateFormat
|
||||
import org.openapitools.client.auth.ApiKeyAuth
|
||||
import org.openapitools.client.auth.Authentication
|
||||
import org.openapitools.client.auth.HttpBasicAuth
|
||||
import org.openapitools.client.auth.HttpBearerAuth
|
||||
import org.openapitools.client.auth.OAuth
|
||||
import org.openapitools.client.auth.*
|
||||
|
||||
open class ApiClient(
|
||||
@ -71,7 +67,7 @@ open class ApiClient(
|
||||
* @param username Username
|
||||
*/
|
||||
fun setUsername(username: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
?: throw Exception("No HTTP basic authentication configured")
|
||||
auth.username = username
|
||||
}
|
||||
@ -82,7 +78,7 @@ open class ApiClient(
|
||||
* @param password Password
|
||||
*/
|
||||
fun setPassword(password: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
?: throw Exception("No HTTP basic authentication configured")
|
||||
auth.password = password
|
||||
}
|
||||
@ -94,7 +90,7 @@ open class ApiClient(
|
||||
* @param paramName The name of the API key parameter, or null or set the first key.
|
||||
*/
|
||||
fun setApiKey(apiKey: String, paramName: String? = null) {
|
||||
val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth?
|
||||
?: throw Exception("No API key authentication configured")
|
||||
auth.apiKey = apiKey
|
||||
}
|
||||
@ -106,7 +102,7 @@ open class ApiClient(
|
||||
* @param paramName The name of the API key parameter, or null or set the first key.
|
||||
*/
|
||||
fun setApiKeyPrefix(apiKeyPrefix: String, paramName: String? = null) {
|
||||
val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth?
|
||||
?: throw Exception("No API key authentication configured")
|
||||
auth.apiKeyPrefix = apiKeyPrefix
|
||||
}
|
||||
@ -117,7 +113,7 @@ open class ApiClient(
|
||||
* @param accessToken Access token
|
||||
*/
|
||||
fun setAccessToken(accessToken: String) {
|
||||
val auth = authentications.values.firstOrNull { it is OAuth } as OAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is OAuth } as OAuth?
|
||||
?: throw Exception("No OAuth2 authentication configured")
|
||||
auth.accessToken = accessToken
|
||||
}
|
||||
@ -128,7 +124,7 @@ open class ApiClient(
|
||||
* @param bearerToken The bearer token.
|
||||
*/
|
||||
fun setBearerToken(bearerToken: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth?
|
||||
?: throw Exception("No Bearer authentication configured")
|
||||
auth.bearerToken = bearerToken
|
||||
}
|
||||
@ -159,8 +155,9 @@ open class ApiClient(
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
setBody(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -8,7 +8,7 @@ wrapper {
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.6.10'
|
||||
ext.ktor_version = '2.0.3'
|
||||
ext.ktor_version = '2.1.2'
|
||||
|
||||
repositories {
|
||||
maven { url "https://repo1.maven.org/maven2" }
|
||||
|
@ -12,6 +12,7 @@ import io.ktor.client.request.parameter
|
||||
import io.ktor.client.request.request
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.http.contentType
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.Parameters
|
||||
@ -27,11 +28,6 @@ import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.fasterxml.jackson.core.util.DefaultIndenter
|
||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
|
||||
import org.openapitools.client.auth.ApiKeyAuth
|
||||
import org.openapitools.client.auth.Authentication
|
||||
import org.openapitools.client.auth.HttpBasicAuth
|
||||
import org.openapitools.client.auth.HttpBearerAuth
|
||||
import org.openapitools.client.auth.OAuth
|
||||
import org.openapitools.client.auth.*
|
||||
|
||||
open class ApiClient(
|
||||
@ -79,7 +75,7 @@ open class ApiClient(
|
||||
* @param username Username
|
||||
*/
|
||||
fun setUsername(username: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
?: throw Exception("No HTTP basic authentication configured")
|
||||
auth.username = username
|
||||
}
|
||||
@ -90,7 +86,7 @@ open class ApiClient(
|
||||
* @param password Password
|
||||
*/
|
||||
fun setPassword(password: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth?
|
||||
?: throw Exception("No HTTP basic authentication configured")
|
||||
auth.password = password
|
||||
}
|
||||
@ -102,7 +98,7 @@ open class ApiClient(
|
||||
* @param paramName The name of the API key parameter, or null or set the first key.
|
||||
*/
|
||||
fun setApiKey(apiKey: String, paramName: String? = null) {
|
||||
val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth?
|
||||
?: throw Exception("No API key authentication configured")
|
||||
auth.apiKey = apiKey
|
||||
}
|
||||
@ -114,7 +110,7 @@ open class ApiClient(
|
||||
* @param paramName The name of the API key parameter, or null or set the first key.
|
||||
*/
|
||||
fun setApiKeyPrefix(apiKeyPrefix: String, paramName: String? = null) {
|
||||
val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth?
|
||||
?: throw Exception("No API key authentication configured")
|
||||
auth.apiKeyPrefix = apiKeyPrefix
|
||||
}
|
||||
@ -125,7 +121,7 @@ open class ApiClient(
|
||||
* @param accessToken Access token
|
||||
*/
|
||||
fun setAccessToken(accessToken: String) {
|
||||
val auth = authentications.values.firstOrNull { it is OAuth } as OAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is OAuth } as OAuth?
|
||||
?: throw Exception("No OAuth2 authentication configured")
|
||||
auth.accessToken = accessToken
|
||||
}
|
||||
@ -136,7 +132,7 @@ open class ApiClient(
|
||||
* @param bearerToken The bearer token.
|
||||
*/
|
||||
fun setBearerToken(bearerToken: String) {
|
||||
val auth = authentications.values.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth?
|
||||
val auth = authentications?.values?.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth?
|
||||
?: throw Exception("No Bearer authentication configured")
|
||||
auth.bearerToken = bearerToken
|
||||
}
|
||||
@ -167,8 +163,9 @@ open class ApiClient(
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
setBody(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -4,13 +4,13 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.FormDataContent
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.PartData
|
||||
import kotlin.Unit
|
||||
@ -146,9 +146,9 @@ open class ApiClient(
|
||||
}
|
||||
this.method = requestConfig.method.httpMethod
|
||||
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH))
|
||||
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
|
||||
this.setBody(body)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -11,8 +11,8 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
|
||||
## Requires
|
||||
|
||||
* Kotlin 1.4.30
|
||||
* Gradle 6.8.3
|
||||
* Kotlin 1.6.10
|
||||
* Gradle 7.5
|
||||
|
||||
## Build
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user