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 b0c5f045795..3c1a0b156fd 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 @@ -343,7 +343,7 @@ import com.squareup.moshi.adapter }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -351,16 +351,16 @@ import com.squareup.moshi.adapter } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 39227c9df0b..757080d7ed1 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 @@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 42e24d04773..90aff170761 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 @@ -156,7 +156,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -164,16 +164,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 39227c9df0b..757080d7ed1 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 @@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 39227c9df0b..757080d7ed1 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 @@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 42e24d04773..90aff170761 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 @@ -156,7 +156,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -164,16 +164,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 39227c9df0b..757080d7ed1 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 @@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 39227c9df0b..757080d7ed1 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 @@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 8b98ee5fe52..e983cd91a2f 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 @@ -176,7 +176,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -184,16 +184,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 de055e08795..18950f7e724 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 @@ -176,7 +176,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -184,16 +184,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 40e0198c1a4..e33a5625aed 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 @@ -182,7 +182,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -190,16 +190,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 06bc7af8cfd..d7c20c5f81d 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 @@ -179,7 +179,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -187,16 +187,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 7fea922b53a..fd43ff24fe2 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 @@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 7fea922b53a..fd43ff24fe2 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 @@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 026b024b61d..be98a7761be 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 @@ -177,7 +177,7 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 7fea922b53a..fd43ff24fe2 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 @@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 dadae38a87c..d87c7b38855 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 @@ -175,7 +175,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -183,16 +183,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 7fea922b53a..fd43ff24fe2 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 @@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 c2fb4091927..69b4dcef602 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 @@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 3f4c82be8ad..ca3a9037de5 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 @@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) 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 7fea922b53a..fd43ff24fe2 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 @@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.headers[ContentType].isNullOrEmpty()) { + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { requestConfig.headers[ContentType] = JsonMediaType } if (requestConfig.headers[Accept].isNullOrEmpty()) { @@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie } val headers = requestConfig.headers - if(headers[ContentType].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Content-Type header. This is required.") - } - - if(headers[Accept].isNullOrEmpty()) { + if (headers[Accept].isNullOrEmpty()) { throw kotlin.IllegalStateException("Missing Accept header. This is required.") } - // TODO: support multiple contentType options here. - val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault()) + } else { + null + } val request = when (requestConfig.method) { RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))