From ff251e32137ee71257f22516686b9e8c386dac90 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Mon, 12 Jun 2023 00:19:32 +0800 Subject: [PATCH] fix(kotlin): set content type on ktor-jvm library --- .../libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache | 2 ++ .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 2 ++ .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 2 ++ .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 2 ++ 4 files changed, 8 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache index de3db091a8fd..8f3d31ad09a8 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache @@ -12,6 +12,7 @@ import io.ktor.client.request.parameter import io.ktor.client.request.request import io.ktor.client.request.setBody import io.ktor.client.statement.HttpResponse +import io.ktor.http.ContentType import io.ktor.http.contentType import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -196,6 +197,7 @@ import {{packageName}}.auth.* this.method = requestConfig.method.httpMethod headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) } if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) { + contentType(ContentType.Application.Json) setBody(body) } } diff --git a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 6e9f06023343..832d78f75809 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -12,6 +12,7 @@ import io.ktor.client.request.parameter import io.ktor.client.request.request import io.ktor.client.request.setBody import io.ktor.client.statement.HttpResponse +import io.ktor.http.ContentType import io.ktor.http.contentType import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -156,6 +157,7 @@ open class ApiClient( this.method = requestConfig.method.httpMethod headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) } if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) { + contentType(ContentType.Application.Json) setBody(body) } } diff --git a/samples/client/petstore/kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 69fcc0ab8547..180e34f6ee7c 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -12,6 +12,7 @@ import io.ktor.client.request.parameter import io.ktor.client.request.request import io.ktor.client.request.setBody import io.ktor.client.statement.HttpResponse +import io.ktor.http.ContentType import io.ktor.http.contentType import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -164,6 +165,7 @@ open class ApiClient( this.method = requestConfig.method.httpMethod headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) } if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) { + contentType(ContentType.Application.Json) setBody(body) } } diff --git a/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 762dad7221a4..be26af2d0c43 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -12,6 +12,7 @@ import io.ktor.client.request.parameter import io.ktor.client.request.request import io.ktor.client.request.setBody import io.ktor.client.statement.HttpResponse +import io.ktor.http.ContentType import io.ktor.http.contentType import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -147,6 +148,7 @@ open class ApiClient( this.method = requestConfig.method.httpMethod headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) } if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) { + contentType(ContentType.Application.Json) setBody(body) } }