forked from loafle/openapi-generator-original
Fix #13369: kotlin-client with okhttp doesn't escape path parameters with slashes correctly (#13370)
* Fix #13369 * Regenarate samples * Fix support for okhttp3
This commit is contained in:
@@ -22,6 +22,7 @@ package org.openapitools.client.apis
|
||||
|
||||
import java.io.IOException
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.HttpUrl
|
||||
|
||||
import org.openapitools.client.models.ModelApiResponse
|
||||
import org.openapitools.client.models.Pet
|
||||
@@ -182,7 +183,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = A
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", petId.toString()),
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -412,7 +413,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = A
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", petId.toString()),
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -555,7 +556,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = A
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", petId.toString()),
|
||||
path = "/pet/{petId}".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -633,11 +634,14 @@ class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = A
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.POST,
|
||||
path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", petId.toString()),
|
||||
path = "/pet/{petId}/uploadImage".replace("{"+"petId"+"}", encodeURIComponent(petId.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String =
|
||||
HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0]
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.openapitools.client.apis
|
||||
|
||||
import java.io.IOException
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.HttpUrl
|
||||
|
||||
import org.openapitools.client.models.Order
|
||||
|
||||
@@ -109,7 +110,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", orderId.toString()),
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", encodeURIComponent(orderId.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -246,7 +247,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", orderId.toString()),
|
||||
path = "/store/order/{orderId}".replace("{"+"orderId"+"}", encodeURIComponent(orderId.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -323,4 +324,7 @@ class StoreApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String =
|
||||
HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0]
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.openapitools.client.apis
|
||||
|
||||
import java.io.IOException
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.HttpUrl
|
||||
|
||||
import org.openapitools.client.models.User
|
||||
|
||||
@@ -310,7 +311,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.DELETE,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", username.toString()),
|
||||
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -380,7 +381,7 @@ class UserApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", username.toString()),
|
||||
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
@@ -591,11 +592,14 @@ class UserApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.PUT,
|
||||
path = "/user/{username}".replace("{"+"username"+"}", username.toString()),
|
||||
path = "/user/{username}".replace("{"+"username"+"}", encodeURIComponent(username.toString())),
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String =
|
||||
HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0]
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
||||
updateAuthParams(requestConfig)
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||
.addEncodedPathSegments(requestConfig.path.trimStart('/'))
|
||||
.apply {
|
||||
requestConfig.query.forEach { query ->
|
||||
query.value.forEach { queryValue ->
|
||||
|
||||
Reference in New Issue
Block a user