From 1b8cc4c9160a96a90fa2517307a18bc364f89f81 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Mon, 9 Mar 2026 13:58:20 +0100 Subject: [PATCH 01/12] Convert static constants to CAPITALS. --- .../libraries/jvm-okhttp/api.mustache | 2 +- .../infrastructure/ApiClient.kt.mustache | 74 +++++++++---------- .../infrastructure/ApiClient.kt.mustache | 4 +- .../infrastructure/ApiClient.kt.mustache | 4 +- 4 files changed, 42 insertions(+), 42 deletions(-) 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 8c2213e586f9..bb12f4ebac55 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 @@ -55,7 +55,7 @@ import {{packageName}}.infrastructure.Serializer {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "{{{basePath}}}") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "{{{basePath}}}") } } 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 2faa8be0068c..35e117ae2738 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 @@ -63,22 +63,22 @@ import com.squareup.moshi.adapter {{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open class ApiClient({{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val baseUrl: String, {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val client: Call.Factory = defaultClient) { {{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKey: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKeyPrefix: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var username: String? = null {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var password: String? = null {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var accessToken: String? = null - {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val baseUrlKey: String = "{{packageName}}.baseUrl" + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultClient: OkHttpClient by lazy { @@ -137,7 +137,7 @@ import com.squareup.moshi.adapter /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -167,7 +167,7 @@ import com.squareup.moshi.adapter if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { {{#moshi}} Serializer.moshi.adapter(Any::class.java).toJson(obj) @@ -191,7 +191,7 @@ import com.squareup.moshi.adapter /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -214,7 +214,7 @@ import com.squareup.moshi.adapter when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -236,7 +236,7 @@ import com.squareup.moshi.adapter } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -261,11 +261,11 @@ import com.squareup.moshi.adapter {{#kotlinx_serialization}} Serializer.kotlinxSerializationJson.encodeToString(content) {{/kotlinx_serialization}} - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @@ -273,7 +273,7 @@ import com.squareup.moshi.adapter {{#moshi}} @OptIn(ExperimentalStdlibApi::class) {{/moshi}} - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body if(body == null) { return null @@ -352,8 +352,8 @@ import com.squareup.moshi.adapter }}{{#jackson}}Serializer.jacksonObjectMapper.readValue(bodyContent, object: TypeReference() {}){{/jackson}}{{! }}{{#kotlinx_serialization}}Serializer.kotlinxSerializationJson.decodeFromString(bodyContent){{/kotlinx_serialization}} } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -394,26 +394,26 @@ import com.squareup.moshi.adapter {{/isApiKey}} {{#isBasic}} {{#isBasicBasic}} - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { username?.let { username -> password?.let { password -> - requestConfig.headers[Authorization] = okhttp3.Credentials.basic(username, password) + requestConfig.headers[AUTHORIZATION] = okhttp3.Credentials.basic(username, password) } } } {{/isBasicBasic}} {{#isBasicBearer}} - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken" + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken" } } {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } {{/isOAuth}} @@ -440,21 +440,21 @@ import com.squareup.moshi.adapter }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -498,7 +498,7 @@ import com.squareup.moshi.adapter val response = client.newCall(request).execute() {{/useCoroutines}} - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache index 94c128e7967d..d2a6fc607259 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache @@ -377,11 +377,11 @@ import okhttp3.MediaType.Companion.toMediaType {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { @JvmStatic - protected val baseUrlKey: String = "{{packageName}}.baseUrl" + protected val BASE_URL_KEY: String = "{{packageName}}.baseUrl" @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "{{{basePath}}}") + System.getProperties().getProperty(BASE_URL_KEY, "{{{basePath}}}") } } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache index 4a82f4680a5e..97fd795df6c3 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache @@ -12,11 +12,11 @@ import com.google.gson.reflect.TypeToken {{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { - {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val baseUrlKey: String = "{{packageName}}.baseUrl" + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "{{{basePath}}}") + System.getProperties().getProperty(BASE_URL_KEY, "{{{basePath}}}") } } From f732b71792958fba647067dd6c5491a9fb15efd2 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Mon, 9 Mar 2026 14:02:23 +0100 Subject: [PATCH 02/12] Bring `responseBody` up-to-speed with regards to response nullability. --- .../jvm-okhttp/infrastructure/ApiClient.kt.mustache | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 35e117ae2738..59bbcd94bda1 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 @@ -98,7 +98,7 @@ import com.squareup.moshi.adapter protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -275,9 +275,8 @@ import com.squareup.moshi.adapter {{/moshi}} protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null From 97ddb8a4e8d2bfc087dc358e91f5cc01233bf3e9 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Mon, 9 Mar 2026 14:15:21 +0100 Subject: [PATCH 03/12] Keep previous constants so not to break existing code. --- .../infrastructure/ApiClient.kt.mustache | 54 +++++++++++++ .../org/openapitools/client/apis/AuthApi.kt | 2 +- .../org/openapitools/client/apis/BodyApi.kt | 2 +- .../org/openapitools/client/apis/FormApi.kt | 2 +- .../org/openapitools/client/apis/HeaderApi.kt | 2 +- .../org/openapitools/client/apis/PathApi.kt | 2 +- .../org/openapitools/client/apis/QueryApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 77 +++++++++---------- .../client/infrastructure/ApiClient.kt | 4 +- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../org/openapitools/client/apis/StuffApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../org/openapitools/client/apis/BirdApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../org/openapitools/client/apis/BirdApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../client/infrastructure/ApiClient.kt | 4 +- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../client/infrastructure/ApiClient.kt | 4 +- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../client/infrastructure/ApiClient.kt | 4 +- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/FakeApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../client/infrastructure/ApiClient.kt | 4 +- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- .../org/openapitools/client/apis/EnumApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 69 ++++++++--------- .../org/openapitools/client/apis/PetApi.kt | 2 +- .../org/openapitools/client/apis/StoreApi.kt | 2 +- .../org/openapitools/client/apis/UserApi.kt | 2 +- .../client/infrastructure/ApiClient.kt | 73 +++++++++--------- 103 files changed, 1096 insertions(+), 1069 deletions(-) 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 59bbcd94bda1..ba315ca37adf 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 @@ -73,6 +73,60 @@ import com.squareup.moshi.adapter protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKey: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKeyPrefix: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var username: String? = null diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/AuthApi.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/AuthApi.kt index e04eeef563ad..7011b6f4b7c6 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/AuthApi.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/AuthApi.kt @@ -40,7 +40,7 @@ open class AuthApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost:3000") } } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/BodyApi.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/BodyApi.kt index a9e6cc649eaf..1289ccfadd5a 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/BodyApi.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/BodyApi.kt @@ -42,7 +42,7 @@ open class BodyApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost:3000") } } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/FormApi.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/FormApi.kt index e51c890865ec..07bfef2d46d0 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/FormApi.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/FormApi.kt @@ -40,7 +40,7 @@ open class FormApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost:3000") } } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/HeaderApi.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/HeaderApi.kt index 13a8335cd837..d59003aac9b6 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/HeaderApi.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/HeaderApi.kt @@ -41,7 +41,7 @@ open class HeaderApi(basePath: kotlin.String = defaultBasePath, client: Call.Fac companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost:3000") } } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/PathApi.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/PathApi.kt index 6894ec04db86..7c2ebfbf3281 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/PathApi.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/PathApi.kt @@ -41,7 +41,7 @@ open class PathApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost:3000") } } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/QueryApi.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/QueryApi.kt index 75cf662eabea..470ff0236f99 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/QueryApi.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/apis/QueryApi.kt @@ -43,7 +43,7 @@ open class QueryApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost:3000") } } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 53456dc6d566..753a77643588 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,23 +283,23 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { username?.let { username -> password?.let { password -> - requestConfig.headers[Authorization] = okhttp3.Credentials.basic(username, password) + requestConfig.headers[AUTHORIZATION] = okhttp3.Credentials.basic(username, password) } } } - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken" + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken" } } } @@ -322,21 +321,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -359,7 +358,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ddf86814d26b..4436428e2289 100644 --- a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -159,11 +159,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://localhost:3000") + System.getProperties().getProperty(BASE_URL_KEY, "http://localhost:3000") } } } diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 9d6ce3bc795d..0657a3706ff7 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -41,7 +41,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 608a208cac4a..39daddb30405 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index f79d5c65abbd..4cd7d6f714a6 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index a901ca43190f..6f6b7b0dd4c6 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index fb57439ae60d..4343d03a91b3 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2ddfd72c32c2..ae239cdd71ab 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index e13b07eb5da7..eb5a1a3ada35 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -40,7 +40,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 608a208cac4a..39daddb30405 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/apis/StuffApi.kt b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/apis/StuffApi.kt index 236318dd4855..7b3573f0b464 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/apis/StuffApi.kt +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/apis/StuffApi.kt @@ -41,7 +41,7 @@ open class StuffApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "https://example.org/v1") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "https://example.org/v1") } } diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 3b5b923b5a27..64e82c2156be 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken" + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken" } } } @@ -315,21 +314,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -352,7 +351,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 556870f29311..b06eaa90af60 100644 --- a/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -101,11 +101,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://example.org") + System.getProperties().getProperty(BASE_URL_KEY, "http://example.org") } } } diff --git a/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 556870f29311..b06eaa90af60 100644 --- a/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -101,11 +101,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://example.org") + System.getProperties().getProperty(BASE_URL_KEY, "http://example.org") } } } diff --git a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt index b12852467001..4fdaf72cb29c 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt @@ -43,7 +43,7 @@ open class BirdApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://example.org") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://example.org") } } diff --git a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 82abe8c6e784..92f067362c2d 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,22 +35,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -70,7 +70,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -109,7 +109,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -139,7 +139,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { // Note: Without a custom serializer, kotlinx.serialization cannot serialize Any? // The custom serializer should be provided at PartConfig creation to capture type info @@ -152,7 +152,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -175,7 +175,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -197,7 +197,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -211,20 +211,19 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.kotlinxSerializationJson.encodeToString(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -286,8 +285,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.kotlinxSerializationJson.decodeFromString(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -307,21 +306,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -344,7 +343,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt index 77824ecc64f5..124dfa2a9699 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/apis/BirdApi.kt @@ -41,7 +41,7 @@ open class BirdApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://example.org") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://example.org") } } diff --git a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 608a208cac4a..39daddb30405 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 56065cde7824..e5ac791dbdb4 100644 --- a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -41,7 +41,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } diff --git a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 608a208cac4a..39daddb30405 100644 --- a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 293fe1a317e8..b3abaeb0baa8 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 @@ -40,7 +40,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } 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 608a208cac4a..39daddb30405 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 8fb4aa9454d9..157d18c96038 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 @@ -41,7 +41,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } 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 608a208cac4a..39daddb30405 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 87e875b42b95..e17c5a0fc211 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 @@ -40,7 +40,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } 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 608a208cac4a..39daddb30405 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index aa1e42bd820d..90ac92c1b344 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -101,11 +101,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://localhost") + System.getProperties().getProperty(BASE_URL_KEY, "http://localhost") } } } 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 6d75872731f8..c073367741eb 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 @@ -41,7 +41,7 @@ open class DefaultApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } 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 608a208cac4a..39daddb30405 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 9faa2eedaf4f..ea1f10b74aa6 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -42,7 +42,7 @@ public open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call public companion object { @JvmStatic public val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 8aa8db04813c..d65fcc4eb6b8 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -41,7 +41,7 @@ public open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Ca public companion object { @JvmStatic public val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index a05b697c7d29..0ee1b7821b99 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -41,7 +41,7 @@ public open class UserApi(basePath: kotlin.String = defaultBasePath, client: Cal public companion object { @JvmStatic public val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 27b2d0a1d647..443c762e7d15 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ public val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() public open class ApiClient(public val baseUrl: String, public val client: Call.Factory = defaultClient) { public companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" public val apiKey: MutableMap = mutableMapOf() public val apiKeyPrefix: MutableMap = mutableMapOf() public var username: String? = null public var password: String? = null public var accessToken: String? = null - public const val baseUrlKey: String = "org.openapitools.client.baseUrl" + public const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic public val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 d5605d2dfb6a..3e919f23e574 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 83f36f7f7765..8a5426ffb6fa 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 59ae1b3fcd8d..af8aecc33c62 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 e4d1d2ec2b5b..6bc241226543 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.gson.toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,20 +208,19 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.gson.toJson(content, T::class.java) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -283,16 +282,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -323,21 +322,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -360,7 +359,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 2ebcca471c90..84d88cfb6673 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 7363f4426a0d..58450b979123 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 22f5496de77e..eb0154b68e09 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 81368b73d125..ccce78a4c0c7 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.jacksonObjectMapper.writeValueAsString(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,20 +208,19 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.jacksonObjectMapper.writeValueAsString(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -283,16 +282,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.jacksonObjectMapper.readValue(bodyContent, object: TypeReference() {}) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -323,21 +322,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -360,7 +359,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 8a466b82b9bc..6317001d87be 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 @@ -44,7 +44,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 8aac14de6e43..fb33481553d3 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 @@ -43,7 +43,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 9fb061238832..8838536653ce 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 @@ -43,7 +43,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 3b8c498e110b..6d41230efaa8 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 @@ -36,22 +36,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -71,7 +71,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -110,7 +110,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -140,7 +140,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { // Note: Without a custom serializer, kotlinx.serialization cannot serialize Any? // The custom serializer should be provided at PartConfig creation to capture type info @@ -153,7 +153,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -176,7 +176,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -198,7 +198,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -212,20 +212,19 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.kotlinxSerializationJson.encodeToString(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -291,16 +290,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.kotlinxSerializationJson.decodeFromString(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -331,21 +330,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -368,7 +367,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 7222dca1706b..5564802e4b32 100644 --- a/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,11 +212,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } 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 9a8e8be9a165..06e917b7c06c 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 @@ -44,7 +44,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 852864017f16..13445b1f3c02 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 @@ -43,7 +43,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 106eb564c083..3e31e0fbcac6 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 @@ -43,7 +43,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 104be9ffad7c..6d6c37d63cef 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 @@ -37,22 +37,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -72,7 +72,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -111,7 +111,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -141,7 +141,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.gson.toJson(obj) } else { @@ -152,7 +152,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -175,7 +175,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -197,7 +197,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -211,20 +211,19 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.gson.toJson(content, T::class.java) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -286,16 +285,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -326,21 +325,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -374,7 +373,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }) } - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index d2a8ee6fbf86..cabfdc7e8d8c 100644 --- a/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -213,11 +213,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } diff --git a/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ed3c8ad3ef0f..fe2698ee15b6 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -7,11 +7,11 @@ import com.google.gson.reflect.TypeToken open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e8b269552d46..c67f28497feb 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -7,11 +7,11 @@ import com.fasterxml.jackson.core.type.TypeReference open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e8b269552d46..c67f28497feb 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -7,11 +7,11 @@ import com.fasterxml.jackson.core.type.TypeReference open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index aa29a11b2b55..e73feb59f996 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -6,11 +6,11 @@ import java.nio.charset.StandardCharsets open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 776939908660..6aef60486835 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 59993ba435a8..17b34e3f7713 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 2deab8c45e8f..eb9b58156696 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 24ba4d333f1b..40bca9025d5c 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 892c6a50d21f..7f073dd8660d 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -232,11 +232,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } 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 39d6444da809..cb2390f6152d 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 d90b515fb867..6e6fe9177c3c 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 f5d3bd69a1b6..ca99d5e78e4c 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 24ba4d333f1b..40bca9025d5c 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 776939908660..6aef60486835 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 59993ba435a8..17b34e3f7713 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 2deab8c45e8f..eb9b58156696 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 24ba4d333f1b..40bca9025d5c 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt index b8965bb2fad9..7ebab165b152 100644 --- a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt +++ b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt @@ -41,7 +41,7 @@ open class FakeApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://localhost") } } diff --git a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 608a208cac4a..39daddb30405 100644 --- a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,8 +283,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -305,21 +304,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -342,7 +341,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 d05e53330e23..473de291ab95 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 @@ -42,7 +42,7 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Fa companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 3e5c75d189b6..82c5de679b02 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 @@ -41,7 +41,7 @@ internal class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call. companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 5f849b170c6f..7193981a896d 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 @@ -41,7 +41,7 @@ internal class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.F companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 8ed3a3eb901a..1e4dc968eb2f 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 @@ -34,22 +34,22 @@ internal val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() internal open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { internal companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 3304b4841795..c3d0dc197da7 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 b9f209eddab5..534aff705f20 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 c26277604c00..a39974198e74 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 24ba4d333f1b..40bca9025d5c 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") diff --git a/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 7222dca1706b..5564802e4b32 100644 --- a/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,11 +212,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } diff --git a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9a4b719801ca..75352f05685e 100644 --- a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,11 +212,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index d9fbeb34f0b3..981e0678a745 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -214,11 +214,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5a6ac9cc7fcb..2a48b462df32 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,11 +212,11 @@ class ApiClient( companion object { @JvmStatic - protected val baseUrlKey: String = "org.openapitools.client.baseUrl" + protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") } } } 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 5d2a69f2177b..483d0f247d5a 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 59993ba435a8..17b34e3f7713 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 2deab8c45e8f..eb9b58156696 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 24ba4d333f1b..40bca9025d5c 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 776939908660..6aef60486835 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 59993ba435a8..17b34e3f7713 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 2deab8c45e8f..eb9b58156696 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 560d92783571..33f76ef7baf5 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 2cd6c8d9af19..a04ef8851e86 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 @@ -43,7 +43,7 @@ open class EnumApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 82abe8c6e784..92f067362c2d 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 @@ -35,22 +35,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -70,7 +70,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -109,7 +109,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -139,7 +139,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { // Note: Without a custom serializer, kotlinx.serialization cannot serialize Any? // The custom serializer should be provided at PartConfig creation to capture type info @@ -152,7 +152,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -175,7 +175,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -197,7 +197,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -211,20 +211,19 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.kotlinxSerializationJson.encodeToString(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -286,8 +285,8 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.kotlinxSerializationJson.decodeFromString(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } @@ -307,21 +306,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -344,7 +343,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") 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 776939908660..6aef60486835 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 @@ -42,7 +42,7 @@ open class PetApi(basePath: kotlin.String = defaultBasePath, client: Call.Factor companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 59993ba435a8..17b34e3f7713 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 @@ -41,7 +41,7 @@ open class StoreApi(basePath: kotlin.String = defaultBasePath, client: Call.Fact companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 2deab8c45e8f..eb9b58156696 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 @@ -41,7 +41,7 @@ open class UserApi(basePath: kotlin.String = defaultBasePath, client: Call.Facto companion object { @JvmStatic val defaultBasePath: String by lazy { - System.getProperties().getProperty(ApiClient.baseUrlKey, "http://petstore.swagger.io/v2") + System.getProperties().getProperty(ApiClient.BASE_URL_KEY, "http://petstore.swagger.io/v2") } } 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 24ba4d333f1b..40bca9025d5c 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 @@ -34,22 +34,22 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" - protected const val TextMediaType: String = "text/plain" + protected const val CONTENT_TYPE: String = "Content-Type" + protected const val ACCEPT: String = "ACCEPT" + protected const val AUTHORIZATION: String = "AUTHORIZATION" + protected const val JSON_MEDIA_TYPE: String = "application/json" + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" + protected const val XML_MEDIA_TYPE: String = "application/xml" + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" + protected const val TEXT_MEDIA_TYPE: String = "text/plain" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val baseUrlKey: String = "org.openapitools.client.baseUrl" + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { @@ -69,7 +69,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) - } catch (io: IOException) { + } catch (_: IOException) { "application/octet-stream" } return contentType @@ -108,7 +108,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds a File to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is a File + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is a File * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -138,7 +138,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (serializer != null) { return serializer(obj) } - + return if (contentType?.contains("json") == true) { Serializer.moshi.adapter(Any::class.java).toJson(obj) } else { @@ -149,7 +149,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie /** * Adds any type to a MultipartBody.Builder * Defined a helper in the requestBody method to not duplicate code - * It will be used when the content is a FormDataMediaType and the body of the PartConfig is not a File. + * It will be used when the content is a `FORM_DATA_MEDIA_TYPE` and the body of the PartConfig is not a File. * * @param name The field name to add in the request * @param headers The headers that are in the PartConfig @@ -172,7 +172,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) - mediaType == FormDataMediaType -> + mediaType == FORM_DATA_MEDIA_TYPE -> MultipartBody.Builder() .setType(MultipartBody.FORM) .apply { @@ -194,7 +194,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } }.build() - mediaType == FormUrlEncMediaType -> { + mediaType == FORM_URL_ENC_MEDIA_TYPE -> { FormBody.Builder().apply { // content's type *must* be Map> @Suppress("UNCHECKED_CAST") @@ -208,21 +208,20 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie EMPTY_REQUEST } else { Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + .toRequestBody((mediaType ?: JSON_MEDIA_TYPE).toMediaTypeOrNull()) } - mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") - mediaType == TextMediaType && content is String -> - content.toRequestBody(TextMediaType.toMediaTypeOrNull()) + mediaType == XML_MEDIA_TYPE -> throw UnsupportedOperationException("xml not currently supported.") + mediaType == TEXT_MEDIA_TYPE && content is String -> + content.toRequestBody(TEXT_MEDIA_TYPE.toMediaTypeOrNull()) // TODO: this should be extended with other serializers else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, text body, byte body and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + protected inline fun responseBody(response: Response, mediaType: String? = JSON_MEDIA_TYPE): T? { val body = response.body - if(body == null) { - return null - } else if (T::class.java == Unit::class.java) { + + if (T::class.java == Unit::class.java) { // No need to parse the body when we're not interested in the body // Useful when API is returning other Content-Type return null @@ -284,16 +283,16 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } Serializer.moshi.adapter().fromJson(bodyContent) } - mediaType == OctetMediaType -> body.bytes() as? T - mediaType == TextMediaType -> body.string() as? T + mediaType == OCTET_MEDIA_TYPE -> body.bytes() as? T + mediaType == TEXT_MEDIA_TYPE -> body.string() as? T else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, text body and byte body.") } } protected fun updateAuthParams(requestConfig: RequestConfig) { - if (requestConfig.headers[Authorization].isNullOrEmpty()) { + if (requestConfig.headers[AUTHORIZATION].isNullOrEmpty()) { accessToken?.let { accessToken -> - requestConfig.headers[Authorization] = "Bearer $accessToken " + requestConfig.headers[AUTHORIZATION] = "Bearer $accessToken " } } if (requestConfig.headers["api_key"].isNullOrEmpty()) { @@ -324,21 +323,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie }.build() // take content-type/accept from spec or set to default (application/json) if not defined - if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { - requestConfig.headers[ContentType] = JsonMediaType + if (requestConfig.body != null && requestConfig.headers[CONTENT_TYPE].isNullOrEmpty()) { + requestConfig.headers[CONTENT_TYPE] = JSON_MEDIA_TYPE } - if (requestConfig.headers[Accept].isNullOrEmpty()) { - requestConfig.headers[Accept] = JsonMediaType + if (requestConfig.headers[ACCEPT].isNullOrEmpty()) { + requestConfig.headers[ACCEPT] = JSON_MEDIA_TYPE } val headers = requestConfig.headers - if (headers[Accept].isNullOrEmpty()) { - throw kotlin.IllegalStateException("Missing Accept header. This is required.") + if (headers[ACCEPT].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing ACCEPT header. This is required.") } - val contentType = if (headers[ContentType] != null) { + val contentType = if (headers[CONTENT_TYPE] != null) { // TODO: support multiple contentType options here. - (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + (headers[CONTENT_TYPE] as String).substringBefore(";").lowercase(Locale.US) } else { null } @@ -361,7 +360,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie val response = client.newCall(request).execute() - val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + val accept = response.header(CONTENT_TYPE)?.substringBefore(";")?.lowercase(Locale.US) // TODO: handle specific mapping types. e.g. Map> @Suppress("UNNECESSARY_SAFE_CALL") From a36ac21579a4a36bdfd72ac727eae0efa90aa3aa Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Mon, 9 Mar 2026 14:17:34 +0100 Subject: [PATCH 04/12] Generate samples code. --- .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ .../client/infrastructure/ApiClient.kt | 54 +++++++++++++++++++ 27 files changed, 1458 insertions(+) diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 753a77643588..f23246916f48 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 39daddb30405..f29ca79fecae 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ae239cdd71ab..aec7ed8c18ad 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 39daddb30405..f29ca79fecae 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 64e82c2156be..a42c478da820 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 92f067362c2d..c55b3936d15a 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -45,6 +45,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 39daddb30405..f29ca79fecae 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 39daddb30405..f29ca79fecae 100644 --- a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 39daddb30405..f29ca79fecae 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 39daddb30405..f29ca79fecae 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 39daddb30405..f29ca79fecae 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 39daddb30405..f29ca79fecae 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 443c762e7d15..fc3739396dd7 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ public open class ApiClient(public val baseUrl: String, public val client: Call. protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + public val apiKey: MutableMap = mutableMapOf() public val apiKeyPrefix: MutableMap = mutableMapOf() public var username: String? = null 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 6bc241226543..6490c0a443f8 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 ccce78a4c0c7..ab900395d129 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 6d41230efaa8..7fd2c5902059 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 @@ -46,6 +46,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 6d6c37d63cef..3408ae32ea7e 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 @@ -47,6 +47,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 40bca9025d5c..837e3f7146c2 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 40bca9025d5c..837e3f7146c2 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 40bca9025d5c..837e3f7146c2 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null diff --git a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 39daddb30405..f29ca79fecae 100644 --- a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 1e4dc968eb2f..2a333142d0c9 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 @@ -44,6 +44,60 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 40bca9025d5c..837e3f7146c2 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 40bca9025d5c..837e3f7146c2 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 33f76ef7baf5..e42ce6e3c4cd 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 92f067362c2d..c55b3936d15a 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 @@ -45,6 +45,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null 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 40bca9025d5c..837e3f7146c2 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 @@ -44,6 +44,60 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" protected const val TEXT_MEDIA_TYPE: String = "text/plain" + @Deprecated( + message = "Please use the capitalized constant `CONTENT_TYPE` instead.", + replaceWith = ReplaceWith("CONTENT_TYPE") + ) + protected const val ContentType: String = CONTENT_TYPE + + @Deprecated( + message = "Please use the capitalized constant `ACCEPT` instead.", + replaceWith = ReplaceWith("ACCEPT") + ) + protected const val Accept: String = ACCEPT + + @Deprecated( + message = "Please use the capitalized constant `AUTHORIZATION` instead.", + replaceWith = ReplaceWith("AUTHORIZATION") + ) + protected const val Authorization: String = AUTHORIZATION + + @Deprecated( + message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("JSON_MEDIA_TYPE") + ) + protected const val JsonMediaType: String = JSON_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") + ) + protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") + ) + protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("XML_MEDIA_TYPE") + ) + protected const val XmlMediaType: String = XML_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") + ) + protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + + @Deprecated( + message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", + replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") + ) + protected const val TextMediaType: String = TEXT_MEDIA_TYPE + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null From c8a93a552ed8b68121bbc0c191482adf8f9900b9 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Mon, 9 Mar 2026 14:49:25 +0100 Subject: [PATCH 05/12] Apply suggestion from @cubic-dev-ai[bot] Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- .../org/openapitools/client/infrastructure/ApiClient.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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 837e3f7146c2..e6ab5258b5b8 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 @@ -105,6 +105,12 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie var accessToken: String? = null const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + @JvmStatic val defaultClient: OkHttpClient by lazy { builder.build() From dc45b56c348e4a987c997370686c4c33b5e8215a Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Mon, 9 Mar 2026 15:10:44 +0100 Subject: [PATCH 06/12] Regenerate sample code. --- .../org/openapitools/client/infrastructure/ApiClient.kt | 6 ------ 1 file changed, 6 deletions(-) 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 e6ab5258b5b8..837e3f7146c2 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 @@ -105,12 +105,6 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie var accessToken: String? = null const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" - @Deprecated( - message = "Please use the capitalized constant `BASE_URL_KEY` instead.", - replaceWith = ReplaceWith("BASE_URL_KEY") - ) - const val baseUrlKey: String = BASE_URL_KEY - @JvmStatic val defaultClient: OkHttpClient by lazy { builder.build() From b02847a798e00e7037a99622f015c058a0de3665 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Tue, 10 Mar 2026 08:48:02 +0100 Subject: [PATCH 07/12] Reorder statics, fix values of `ACCEPT` and `AUTHORIZATION` constants. --- .../infrastructure/ApiClient.kt.mustache | 25 +++++++++++-------- .../infrastructure/ApiClient.kt.mustache | 6 +++++ 2 files changed, 21 insertions(+), 10 deletions(-) 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 ba315ca37adf..0a0b7fc303f5 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 @@ -64,75 +64,80 @@ import com.squareup.moshi.adapter {{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open class ApiClient({{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val baseUrl: String, {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val client: Call.Factory = defaultClient) { {{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val baseUrlKey: String = BASE_URL_KEY + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKey: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val apiKeyPrefix: MutableMap = mutableMapOf() {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var username: String? = null {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var password: String? = null {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var accessToken: String? = null - {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultClient: OkHttpClient by lazy { diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache index 97fd795df6c3..94126c253dfc 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache @@ -14,6 +14,12 @@ import com.google.gson.reflect.TypeToken {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val baseUrlKey: String = BASE_URL_KEY + @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultBasePath: String by lazy { System.getProperties().getProperty(BASE_URL_KEY, "{{{basePath}}}") From eae1eec06b3fc5791f81d6956c8fbe8be633bb7e Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Tue, 10 Mar 2026 08:48:16 +0100 Subject: [PATCH 08/12] Regenerate sample code. --- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 6 +++++ .../client/infrastructure/ApiClient.kt | 6 +++++ .../client/infrastructure/ApiClient.kt | 6 +++++ .../client/infrastructure/ApiClient.kt | 6 +++++ .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- .../client/infrastructure/ApiClient.kt | 25 +++++++++++-------- 31 files changed, 429 insertions(+), 270 deletions(-) diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f23246916f48..b8085ef31f75 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f29ca79fecae..c78ab5e0d9ef 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index aec7ed8c18ad..b6fabcf91636 100644 --- a/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f29ca79fecae..c78ab5e0d9ef 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a42c478da820..c7334e173bcd 100644 --- a/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c55b3936d15a..cccc180e9524 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -36,75 +36,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f29ca79fecae..c78ab5e0d9ef 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f29ca79fecae..c78ab5e0d9ef 100644 --- a/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 f29ca79fecae..c78ab5e0d9ef 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 f29ca79fecae..c78ab5e0d9ef 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 f29ca79fecae..c78ab5e0d9ef 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 f29ca79fecae..c78ab5e0d9ef 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index fc3739396dd7..de25fbf36665 100644 --- a/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ public val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() public open class ApiClient(public val baseUrl: String, public val client: Call.Factory = defaultClient) { public companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + public const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + public const val baseUrlKey: String = BASE_URL_KEY + public val apiKey: MutableMap = mutableMapOf() public val apiKeyPrefix: MutableMap = mutableMapOf() public var username: String? = null public var password: String? = null public var accessToken: String? = null - public const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic public val defaultClient: OkHttpClient by lazy { 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 6490c0a443f8..df427adfe681 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 ab900395d129..b74ee7ab19e9 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 7fd2c5902059..b5cbd5bd1cb4 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 @@ -37,75 +37,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 3408ae32ea7e..fe635449f668 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 @@ -38,75 +38,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index fe2698ee15b6..ab4e04daa49e 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -9,6 +9,12 @@ open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessTo companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + @JvmStatic val defaultBasePath: String by lazy { System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c67f28497feb..cee491a876ef 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -9,6 +9,12 @@ open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessTo companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + @JvmStatic val defaultBasePath: String by lazy { System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c67f28497feb..cee491a876ef 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -9,6 +9,12 @@ open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessTo companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + @JvmStatic val defaultBasePath: String by lazy { System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") diff --git a/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e73feb59f996..b7a32e0f78ef 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -8,6 +8,12 @@ open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessTo companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + @JvmStatic val defaultBasePath: String by lazy { System.getProperties().getProperty(BASE_URL_KEY, "http://petstore.swagger.io/v2") diff --git a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 837e3f7146c2..879f5998dfcd 100644 --- a/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 837e3f7146c2..879f5998dfcd 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 837e3f7146c2..879f5998dfcd 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { diff --git a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f29ca79fecae..c78ab5e0d9ef 100644 --- a/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 2a333142d0c9..41ca6b16533d 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 @@ -35,75 +35,80 @@ internal val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() internal open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { internal companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 837e3f7146c2..879f5998dfcd 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 837e3f7146c2..879f5998dfcd 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 e42ce6e3c4cd..7322b44ff2c2 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 c55b3936d15a..cccc180e9524 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 @@ -36,75 +36,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { 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 837e3f7146c2..879f5998dfcd 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 @@ -35,75 +35,80 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { protected const val CONTENT_TYPE: String = "Content-Type" - protected const val ACCEPT: String = "ACCEPT" - protected const val AUTHORIZATION: String = "AUTHORIZATION" - protected const val JSON_MEDIA_TYPE: String = "application/json" - protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" - protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" - protected const val XML_MEDIA_TYPE: String = "application/xml" - protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" - protected const val TEXT_MEDIA_TYPE: String = "text/plain" - @Deprecated( message = "Please use the capitalized constant `CONTENT_TYPE` instead.", replaceWith = ReplaceWith("CONTENT_TYPE") ) protected const val ContentType: String = CONTENT_TYPE + protected const val ACCEPT: String = "Accept" @Deprecated( message = "Please use the capitalized constant `ACCEPT` instead.", replaceWith = ReplaceWith("ACCEPT") ) protected const val Accept: String = ACCEPT + protected const val AUTHORIZATION: String = "Authorization" @Deprecated( message = "Please use the capitalized constant `AUTHORIZATION` instead.", replaceWith = ReplaceWith("AUTHORIZATION") ) protected const val Authorization: String = AUTHORIZATION + protected const val JSON_MEDIA_TYPE: String = "application/json" @Deprecated( message = "Please use the capitalized constant `JSON_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("JSON_MEDIA_TYPE") ) protected const val JsonMediaType: String = JSON_MEDIA_TYPE + protected const val FORM_DATA_MEDIA_TYPE: String = "multipart/form-data" @Deprecated( message = "Please use the capitalized constant `FORM_DATA_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_DATA_MEDIA_TYPE") ) protected const val FormDataMediaType: String = FORM_DATA_MEDIA_TYPE + protected const val FORM_URL_ENC_MEDIA_TYPE: String = "application/x-www-form-urlencoded" @Deprecated( message = "Please use the capitalized constant `FORM_URL_ENC_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("FORM_URL_ENC_MEDIA_TYPE") ) protected const val FormUrlEncMediaType: String = FORM_URL_ENC_MEDIA_TYPE + protected const val XML_MEDIA_TYPE: String = "application/xml" @Deprecated( message = "Please use the capitalized constant `XML_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("XML_MEDIA_TYPE") ) protected const val XmlMediaType: String = XML_MEDIA_TYPE + protected const val OCTET_MEDIA_TYPE: String = "application/octet-stream" @Deprecated( message = "Please use the capitalized constant `OCTET_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("OCTET_MEDIA_TYPE") ) protected const val OctetMediaType: String = OCTET_MEDIA_TYPE + protected const val TEXT_MEDIA_TYPE: String = "text/plain" @Deprecated( message = "Please use the capitalized constant `TEXT_MEDIA_TYPE` instead.", replaceWith = ReplaceWith("TEXT_MEDIA_TYPE") ) protected const val TextMediaType: String = TEXT_MEDIA_TYPE + const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + const val baseUrlKey: String = BASE_URL_KEY + val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() var username: String? = null var password: String? = null var accessToken: String? = null - const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @JvmStatic val defaultClient: OkHttpClient by lazy { From d7982596e3305c49c2bb282a3bc5d8e6cf6220e2 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Tue, 10 Mar 2026 08:55:08 +0100 Subject: [PATCH 09/12] Add deprecation constant. --- .../jvm-retrofit2/infrastructure/ApiClient.kt.mustache | 8 +++++++- .../jvm-vertx/infrastructure/ApiClient.kt.mustache | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache index d2a6fc607259..af1dbc572cd1 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache @@ -377,7 +377,13 @@ import okhttp3.MediaType.Companion.toMediaType {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { @JvmStatic - protected val BASE_URL_KEY: String = "{{packageName}}.baseUrl" + protected const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val defaultBasePath: String by lazy { diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache index 94126c253dfc..f87f194a6f42 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache @@ -13,7 +13,6 @@ import com.google.gson.reflect.TypeToken {{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" - @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") From d24d0c4ba4e22b078b99a4b8638abb428099aba7 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Tue, 10 Mar 2026 08:55:15 +0100 Subject: [PATCH 10/12] Regenerate sample code. --- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 1 - .../org/openapitools/client/infrastructure/ApiClient.kt | 1 - .../org/openapitools/client/infrastructure/ApiClient.kt | 1 - .../org/openapitools/client/infrastructure/ApiClient.kt | 1 - .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- .../org/openapitools/client/infrastructure/ApiClient.kt | 8 +++++++- 15 files changed, 77 insertions(+), 15 deletions(-) diff --git a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 4436428e2289..636f6e5e8a88 100644 --- a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -159,7 +159,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index b06eaa90af60..538065949469 100644 --- a/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -101,7 +101,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index b06eaa90af60..538065949469 100644 --- a/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -101,7 +101,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 90ac92c1b344..84114aebdd43 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -101,7 +101,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5564802e4b32..2f871252ca16 100644 --- a/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,7 +212,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cabfdc7e8d8c..baab03ca62f8 100644 --- a/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -213,7 +213,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ab4e04daa49e..5f7a51d660ae 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -8,7 +8,6 @@ import com.google.gson.reflect.TypeToken open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" - @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cee491a876ef..e5793db7cc5f 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -8,7 +8,6 @@ import com.fasterxml.jackson.core.type.TypeReference open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" - @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") diff --git a/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cee491a876ef..e5793db7cc5f 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -8,7 +8,6 @@ import com.fasterxml.jackson.core.type.TypeReference open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" - @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") diff --git a/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index b7a32e0f78ef..a258b2d43f46 100644 --- a/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-vertx-moshi/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -7,7 +7,6 @@ import java.nio.charset.StandardCharsets open class ApiClient(val basePath: kotlin.String = defaultBasePath, val accessToken: String? = null, val apiKey: MutableMap = mutableMapOf(), val apiKeyPrefix: MutableMap = mutableMapOf(), var username: String? = null, var password: String? = null, val vertx: Vertx) { companion object { const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" - @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 7f073dd8660d..2461ced8464b 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -232,7 +232,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5564802e4b32..2f871252ca16 100644 --- a/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,7 +212,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 75352f05685e..59065a81f100 100644 --- a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,7 +212,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 981e0678a745..a2f66c9c8507 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -214,7 +214,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2a48b462df32..cf3e50e745cb 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,7 +212,13 @@ class ApiClient( companion object { @JvmStatic - protected val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" + @Deprecated( + message = "Please use the capitalized constant `BASE_URL_KEY` instead.", + replaceWith = ReplaceWith("BASE_URL_KEY") + ) + @JvmStatic + protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic val defaultBasePath: String by lazy { From b674d41af2f3d58a5d2adea9d996c736b0b69149 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Tue, 10 Mar 2026 12:41:42 +0100 Subject: [PATCH 11/12] Remove unnecessary annotation. --- .../jvm-retrofit2/infrastructure/ApiClient.kt.mustache | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache index af1dbc572cd1..c48089c023d9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache @@ -376,13 +376,11 @@ import okhttp3.MediaType.Companion.toMediaType } {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "{{packageName}}.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic From 53460c799a4387aa3363f98493bb09f013f05b62 Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Tue, 10 Mar 2026 12:42:36 +0100 Subject: [PATCH 12/12] Regenerate samples code. --- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 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 -- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 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 -- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 2 -- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 2 -- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 2 -- 11 files changed, 22 deletions(-) diff --git a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 636f6e5e8a88..696797f37b1c 100644 --- a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,13 +158,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 538065949469..54844953f228 100644 --- a/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -100,13 +100,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 538065949469..54844953f228 100644 --- a/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -100,13 +100,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 84114aebdd43..e8455b97d3b3 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -100,13 +100,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2f871252ca16..8ed82e2fd3c0 100644 --- a/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -211,13 +211,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index baab03ca62f8..6ecab1d71386 100644 --- a/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-retrofit2-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -212,13 +212,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2461ced8464b..085e5e1fe1e2 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -231,13 +231,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 2f871252ca16..8ed82e2fd3c0 100644 --- a/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -211,13 +211,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 59065a81f100..fb54a80fbf62 100644 --- a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -211,13 +211,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a2f66c9c8507..ad0963420783 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -213,13 +213,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cf3e50e745cb..657d49349d0f 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -211,13 +211,11 @@ class ApiClient( } companion object { - @JvmStatic protected const val BASE_URL_KEY: String = "org.openapitools.client.baseUrl" @Deprecated( message = "Please use the capitalized constant `BASE_URL_KEY` instead.", replaceWith = ReplaceWith("BASE_URL_KEY") ) - @JvmStatic protected const val baseUrlKey: String = BASE_URL_KEY @JvmStatic