diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache index 46312955403..0b49b95bc29 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache @@ -3,6 +3,7 @@ package {{apiPackage}} import java.io.IOException import okhttp3.OkHttpClient +import okhttp3.HttpUrl {{#imports}}import {{import}} {{/imports}} @@ -224,7 +225,7 @@ import {{packageName}}.infrastructure.toMultiValue return RequestConfig( method = RequestMethod.{{httpMethod}}, - path = "{{path}}"{{#pathParams}}.replace("{"+"{{baseName}}"+"}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}{{{paramName}}}{{#isEnum}}.value{{/isEnum}}.toString(){{/isContainer}}){{/pathParams}}, + path = "{{path}}"{{#pathParams}}.replace("{"+"{{baseName}}"+"}", encodeURIComponent({{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}{{{paramName}}}{{#isEnum}}.value{{/isEnum}}.toString(){{/isContainer}})){{/pathParams}}, query = localVariableQuery, headers = localVariableHeaders, body = localVariableBody @@ -232,5 +233,8 @@ import {{packageName}}.infrastructure.toMultiValue } {{/operation}} + + private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String = + HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments{{#jvm-okhttp3}}(){{/jvm-okhttp3}}[0] } {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index d61913ce869..915fa58d22e 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -313,7 +313,7 @@ import com.squareup.moshi.adapter {{/hasAuthMethods}} val url = httpUrl.newBuilder() - .addPathSegments(requestConfig.path.trimStart('/')) + .addEncodedPathSegments(requestConfig.path.trimStart('/')) .apply { requestConfig.query.forEach { query -> query.value.forEach { queryValue -> diff --git a/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt b/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt index eaed334ee14..f10b0c29ea7 100644 --- a/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt +++ b/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt @@ -22,6 +22,7 @@ package org.openapitools.client.apis import java.io.IOException import okhttp3.OkHttpClient +import okhttp3.HttpUrl import org.openapitools.client.models.Bird @@ -112,11 +113,14 @@ class BirdApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = return RequestConfig( method = RequestMethod.GET, - path = "/v1/bird/{id}".replace("{"+"id"+"}", id.toString()), + path = "/v1/bird/{id}".replace("{"+"id"+"}", encodeURIComponent(id.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] } diff --git a/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bfd00ac6a2e..fc978529811 100644 --- a/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 50854f326ba..264f49e0342 100644 --- a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -22,6 +22,7 @@ package org.openapitools.client.apis import java.io.IOException import okhttp3.OkHttpClient +import okhttp3.HttpUrl import com.squareup.moshi.Json @@ -108,11 +109,14 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient return RequestConfig( method = RequestMethod.GET, - path = "/{ids}".replace("{"+"ids"+"}", ids.joinToString(",")), + path = "/{ids}".replace("{"+"ids"+"}", encodeURIComponent(ids.joinToString(","))), 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] } diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 6db8e7c74f2..68b873ff5fd 100644 --- a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -143,7 +143,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie val httpUrl = HttpUrl.parse(baseUrl) ?: 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 -> diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 50854f326ba..7fb1fe13aeb 100644 --- a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -22,6 +22,7 @@ package org.openapitools.client.apis import java.io.IOException import okhttp3.OkHttpClient +import okhttp3.HttpUrl import com.squareup.moshi.Json @@ -108,11 +109,14 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient return RequestConfig( method = RequestMethod.GET, - path = "/{ids}".replace("{"+"ids"+"}", ids.joinToString(",")), + path = "/{ids}".replace("{"+"ids"+"}", encodeURIComponent(ids.joinToString(","))), 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] } diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bfd00ac6a2e..fc978529811 100644 --- a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index a9d705e8571..53af17ba65d 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -22,6 +22,7 @@ package org.openapitools.client.apis import java.io.IOException import okhttp3.OkHttpClient +import okhttp3.HttpUrl import org.openapitools.client.models.Apa @@ -117,4 +118,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] } diff --git a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bfd00ac6a2e..fc978529811 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index be89177b3fb..868e1f105e6 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 6db8e7c74f2..68b873ff5fd 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -143,7 +143,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie val httpUrl = HttpUrl.parse(baseUrl) ?: 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 -> diff --git a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index be89177b3fb..16fadc95fb7 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bfd00ac6a2e..fc978529811 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 28d89352515..e03a1d62e58 100644 --- a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bfd00ac6a2e..fc978529811 100644 --- a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 63bbe32b4f9..fe9b071b102 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index f9fc75b2858..c2ac779c7ba 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index df52c3c9b37..8092ac6b381 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 17485b2c887..ec0a443253c 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -163,7 +163,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 -> diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index fd8229183ad..c4837b83581 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 404bb6024c3..df9210606cf 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 2d24c96c09e..bf0d42979b2 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5040c47697c..404ba01dd99 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -163,7 +163,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 -> diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 3f02a9e0e6f..45b16f79d96 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index d951868b34c..d6d0335a5d7 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 8e96a200f7d..ba683f46c47 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index d692b5fad98..916312c0478 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 81fdbed46ab..616482dd348 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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 @@ -184,7 +185,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 @@ -414,7 +415,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 @@ -557,7 +558,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 @@ -635,11 +636,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] } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 51255cd2a5d..851a21bb0ed 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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 @@ -111,7 +112,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 @@ -248,7 +249,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 @@ -325,4 +326,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] } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 834bbe6f813..0fc876f8217 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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 @@ -312,7 +313,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 @@ -382,7 +383,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 @@ -593,11 +594,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] } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cacd2b743b3..452d68570bd 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -166,7 +166,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 -> diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index bc6cf14b7e8..5f4eb43ae36 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 2fc4f74b3d1..0a52fd59c92 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index c75da6a2b44..0ef99da52c6 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 4ad22a02df0..fa5c0777627 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e0d26a4ae3b..8469d95fa3a 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index d192191c850..d2af06d3eed 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 327a69c8e7e..2564e3b1d3a 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 4ad22a02df0..fa5c0777627 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index ca615c5e8e9..b8019bf171a 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpC 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 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpC 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 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpC 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 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath, client: OkHttpC 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] } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index fef010230c8..fea1acfa450 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath, client: OkHtt 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 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath, client: OkHtt 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 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath, client: OkHtt ) } + + private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String = + HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0] } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 03ef7baa872..1cb158f290a 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath, client: OkHttp 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 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath, client: OkHttp 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 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath, client: OkHttp 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] } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 61ba8e30416..3a26e6b545f 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -164,7 +164,7 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de updateAuthParams(requestConfig) val url = httpUrl.newBuilder() - .addPathSegments(requestConfig.path.trimStart('/')) + .addEncodedPathSegments(requestConfig.path.trimStart('/')) .apply { requestConfig.query.forEach { query -> query.value.forEach { queryValue -> diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index aeb395cf872..02986f560d8 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index cf9f7f99e49..9f9e6f35919 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 2c46e94f7fc..1d72bd95513 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 4ad22a02df0..fa5c0777627 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 3e28ded0d98..3d04753cabd 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index d192191c850..ae79117268a 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 327a69c8e7e..136d52719e1 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9fcf1385050..f7997adfe2e 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -162,7 +162,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 -> diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index bf195c9af2e..a218d0c44e3 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index d192191c850..d2af06d3eed 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 327a69c8e7e..2564e3b1d3a 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 4ad22a02df0..fa5c0777627 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e0d26a4ae3b..8469d95fa3a 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index d192191c850..d2af06d3eed 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 327a69c8e7e..2564e3b1d3a 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3d6b7ccb792..8fdd4f5cbfb 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/apis/EnumApi.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/apis/EnumApi.kt index 56c1dfb819b..acecb76a6b9 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/apis/EnumApi.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/apis/EnumApi.kt @@ -22,6 +22,7 @@ package org.openapitools.client.apis import java.io.IOException import okhttp3.OkHttpClient +import okhttp3.HttpUrl import org.openapitools.client.models.PetEnum @@ -117,4 +118,7 @@ class EnumApi(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] } diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3d056f549d6..ac7394b1577 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 -> diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e0d26a4ae3b..8469d95fa3a 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index d192191c850..d2af06d3eed 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 327a69c8e7e..2564e3b1d3a 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -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] } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 4ad22a02df0..fa5c0777627 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -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 ->