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.ModelWithEnumPropertyHavingDefault
@@ -116,4 +117,7 @@ class DefaultApi(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

@@ -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 ->