forked from loafle/openapi-generator-original
[kotlin-client][jvm-spring-*] Fixed URL encoding (#17493)
* [kotlin-client][jvm-spring-*] do URL encoding via the UrlBuilder instead of manual replacement * [kotlin-client][jvm-spring-*] Fixed imports * ensure up-to-date * Fixed syntax problem * Removed unnecessary toString()
This commit is contained in:
@@ -24,6 +24,7 @@ import org.springframework.http.codec.json.Jackson2JsonEncoder
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.http.MediaType
|
||||
import reactor.core.publisher.Mono
|
||||
import org.springframework.util.LinkedMultiValueMap
|
||||
|
||||
import org.openapitools.client.models.ModelApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
@@ -63,9 +64,13 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
localVariableHeaders["Content-Type"] = "application/xml"
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -94,9 +99,14 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
apiKey?.apply { localVariableHeaders["api_key"] = this.toString() }
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"petId" to petId,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
path = "/pet/{petId}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -137,9 +147,13 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/findByStatus",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -174,9 +188,13 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/findByTags",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -205,9 +223,14 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"petId" to petId,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
path = "/pet/{petId}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -238,9 +261,13 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
localVariableHeaders["Content-Type"] = "application/xml"
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/pet",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -270,9 +297,14 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded")
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"petId" to petId,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
path = "/pet/{petId}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -303,9 +335,14 @@ class PetApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "multipart/form-data")
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"petId" to petId,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
path = "/pet/{petId}/uploadImage",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.http.codec.json.Jackson2JsonEncoder
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.http.MediaType
|
||||
import reactor.core.publisher.Mono
|
||||
import org.springframework.util.LinkedMultiValueMap
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
import org.openapitools.client.infrastructure.*
|
||||
@@ -59,9 +60,14 @@ class StoreApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"orderId" to orderId,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", encodeURIComponent(orderId.toString())),
|
||||
path = "/store/order/{orderId}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = false,
|
||||
@@ -90,9 +96,13 @@ class StoreApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/store/inventory",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -121,9 +131,14 @@ class StoreApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"orderId" to orderId,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", encodeURIComponent(orderId.toString())),
|
||||
path = "/store/order/{orderId}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = false,
|
||||
@@ -153,9 +168,13 @@ class StoreApi(client: WebClient) : ApiClient(client) {
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/store/order",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = false,
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.http.codec.json.Jackson2JsonEncoder
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.http.MediaType
|
||||
import reactor.core.publisher.Mono
|
||||
import org.springframework.util.LinkedMultiValueMap
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
import org.openapitools.client.infrastructure.*
|
||||
@@ -60,9 +61,13 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -91,9 +96,13 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user/createWithArray",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -122,9 +131,13 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/user/createWithList",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -152,9 +165,14 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"username" to username,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
|
||||
path = "/user/{username}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -183,9 +201,14 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"username" to username,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
|
||||
path = "/user/{username}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = false,
|
||||
@@ -218,9 +241,13 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Accept"] = "application/xml, application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/login",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = false,
|
||||
@@ -248,9 +275,13 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/logout",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
@@ -279,9 +310,14 @@ class UserApi(client: WebClient) : ApiClient(client) {
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
localVariableHeaders["Content-Type"] = "application/json"
|
||||
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"username" to username,
|
||||
)
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
|
||||
path = "/user/{username}",
|
||||
params = params,
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
requiresAuthentication = true,
|
||||
|
||||
@@ -4,9 +4,9 @@ import org.springframework.core.ParameterizedTypeReference
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.web.util.UriUtils
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.util.LinkedMultiValueMap
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
open class ApiClient(protected val client: WebClient) {
|
||||
@@ -33,19 +33,15 @@ open class ApiClient(protected val client: WebClient) {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun encodeURIComponent(uriComponent: kotlin.String) =
|
||||
UriUtils.encodeFragment(uriComponent, Charsets.UTF_8)
|
||||
|
||||
private fun <I> WebClient.method(requestConfig: RequestConfig<I>)=
|
||||
method(HttpMethod.valueOf(requestConfig.method.name))
|
||||
|
||||
private fun <I> WebClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>) =
|
||||
uri { builder ->
|
||||
builder.path(requestConfig.path).apply {
|
||||
requestConfig.query.forEach { (name, value) ->
|
||||
queryParam(name, value)
|
||||
}
|
||||
}.build()
|
||||
builder
|
||||
.path(requestConfig.path)
|
||||
.queryParams(LinkedMultiValueMap(requestConfig.query))
|
||||
.build(requestConfig.params)
|
||||
}
|
||||
|
||||
private fun <I> WebClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
||||
|
||||
@@ -12,6 +12,7 @@ data class RequestConfig<T>(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val params: MutableMap<String, Any> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
||||
val requiresAuthentication: Boolean,
|
||||
val body: T? = null
|
||||
|
||||
Reference in New Issue
Block a user