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 com.squareup.moshi.Json
@@ -227,11 +228,14 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient
return RequestConfig(
method = RequestMethod.POST,
path = "/test".replace("{"+"pi0"+"}", pi0.toString()).replace("{"+"pi1"+"}", pi1.toString()).replace("{"+"pn0"+"}", pn0.toString()).replace("{"+"pn1"+"}", pn1.toString()),
path = "/test".replace("{"+"pi0"+"}", encodeURIComponent(pi0.toString())).replace("{"+"pi1"+"}", encodeURIComponent(pi1.toString())).replace("{"+"pn0"+"}", encodeURIComponent(pn0.toString())).replace("{"+"pn1"+"}", encodeURIComponent(pn1.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

@@ -145,7 +145,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
val url = httpUrl.newBuilder()
.addPathSegments(requestConfig.path.trimStart('/'))
.addEncodedPathSegments(requestConfig.path.trimStart('/'))
.apply {
requestConfig.query.forEach { query ->
query.value.forEach { queryValue ->