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:
Segev Finer
2022-09-09 11:31:31 +03:00
committed by GitHub
parent 0b6604504c
commit 9753086bcb
66 changed files with 315 additions and 135 deletions

View File

@@ -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
@@ -183,7 +184,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
@@ -406,7 +407,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
@@ -549,7 +550,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
@@ -627,11 +628,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]
}

View File

@@ -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
@@ -110,7 +111,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
@@ -247,7 +248,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
@@ -324,4 +325,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]
}

View File

@@ -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
@@ -311,7 +312,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
@@ -381,7 +382,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
@@ -592,11 +593,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]
}

View File

@@ -169,7 +169,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 ->