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 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]
|
||||
}
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user