forked from loafle/openapi-generator-original
[kotlin][client] only use authentication tokens when they are not null (#4238)
* [kotlin-client] only use authentication tokens when they are not null * [kotlin-client] only use authentication tokens when they are not null
This commit is contained in:
parent
fbf3d593df
commit
620aa4fd5e
@ -130,19 +130,27 @@ import java.io.File
|
|||||||
{{#isBasic}}
|
{{#isBasic}}
|
||||||
{{^isBasicBearer}}
|
{{^isBasicBearer}}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
username?.let { username ->
|
||||||
|
password?.let { password ->
|
||||||
requestConfig.headers[Authorization] = Credentials.basic(username, password)
|
requestConfig.headers[Authorization] = Credentials.basic(username, password)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{#isBasicBearer}}
|
{{#isBasicBearer}}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,10 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2")
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun findPetsByStatus(status: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
fun findPetsByStatus(status: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
||||||
val localVariableBody: kotlin.Any? = null
|
val localVariableBody: kotlin.Any? = null
|
||||||
val localVariableQuery: MultiValueMap = mapOf("status" to toMultiValue(status.toList(), "csv"))
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
put("status", toMultiValue(status.toList(), "csv"))
|
||||||
|
}
|
||||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||||
val localVariableConfig = RequestConfig(
|
val localVariableConfig = RequestConfig(
|
||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
@ -129,7 +132,10 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2")
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun findPetsByTags(tags: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
fun findPetsByTags(tags: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
||||||
val localVariableBody: kotlin.Any? = null
|
val localVariableBody: kotlin.Any? = null
|
||||||
val localVariableQuery: MultiValueMap = mapOf("tags" to toMultiValue(tags.toList(), "csv"))
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
put("tags", toMultiValue(tags.toList(), "csv"))
|
||||||
|
}
|
||||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||||
val localVariableConfig = RequestConfig(
|
val localVariableConfig = RequestConfig(
|
||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
|
@ -188,7 +188,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2"
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||||
val localVariableBody: kotlin.Any? = null
|
val localVariableBody: kotlin.Any? = null
|
||||||
val localVariableQuery: MultiValueMap = mapOf("username" to listOf("$username"), "password" to listOf("$password"))
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
put("username", listOf(username.toString()))
|
||||||
|
put("password", listOf(password.toString()))
|
||||||
|
}
|
||||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||||
val localVariableConfig = RequestConfig(
|
val localVariableConfig = RequestConfig(
|
||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
|
@ -83,9 +83,11 @@ internal open class ApiClient(val baseUrl: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
@ -98,7 +98,10 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun findPetsByStatus(status: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
fun findPetsByStatus(status: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
||||||
val localVariableBody: kotlin.Any? = null
|
val localVariableBody: kotlin.Any? = null
|
||||||
val localVariableQuery: MultiValueMap = mapOf("status" to toMultiValue(status.toList(), "csv"))
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
put("status", toMultiValue(status.toList(), "csv"))
|
||||||
|
}
|
||||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||||
val localVariableConfig = RequestConfig(
|
val localVariableConfig = RequestConfig(
|
||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
@ -129,7 +132,10 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun findPetsByTags(tags: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
fun findPetsByTags(tags: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
||||||
val localVariableBody: kotlin.Any? = null
|
val localVariableBody: kotlin.Any? = null
|
||||||
val localVariableQuery: MultiValueMap = mapOf("tags" to toMultiValue(tags.toList(), "csv"))
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
put("tags", toMultiValue(tags.toList(), "csv"))
|
||||||
|
}
|
||||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||||
val localVariableConfig = RequestConfig(
|
val localVariableConfig = RequestConfig(
|
||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
|
@ -188,7 +188,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String {
|
||||||
val localVariableBody: kotlin.Any? = null
|
val localVariableBody: kotlin.Any? = null
|
||||||
val localVariableQuery: MultiValueMap = mapOf("username" to listOf("$username"), "password" to listOf("$password"))
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
put("username", listOf(username.toString()))
|
||||||
|
put("password", listOf(password.toString()))
|
||||||
|
}
|
||||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||||
val localVariableConfig = RequestConfig(
|
val localVariableConfig = RequestConfig(
|
||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
|
@ -81,9 +81,11 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||||
val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.")
|
val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
@ -83,9 +83,11 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
@ -83,9 +83,11 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
@ -83,9 +83,11 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
if (requestConfig.headers[Authorization].isNullOrEmpty()) {
|
||||||
|
accessToken?.let { accessToken ->
|
||||||
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
requestConfig.headers[Authorization] = "Bearer " + accessToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig, body : Any? = null): ApiInfrastructureResponse<T?> {
|
||||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user