diff --git a/bin/kotlin-uppercase-enum.sh b/bin/kotlin-client-uppercase-enum.sh similarity index 89% rename from bin/kotlin-uppercase-enum.sh rename to bin/kotlin-client-uppercase-enum.sh index 49f690283f4..7f456fc3a06 100755 --- a/bin/kotlin-uppercase-enum.sh +++ b/bin/kotlin-client-uppercase-enum.sh @@ -31,4 +31,4 @@ ags="generate -t modules/openapi-generator/src/main/resources/kotlin-client -i m java ${JAVA_OPTS} -jar ${executable} ${ags} -cp CI/samples.ci/client/petstore/kotlin-uppercase-enum/pom.xml samples/client/petstore/kotlin-uppercase-enum/pom.xml \ No newline at end of file +#cp CI/samples.ci/client/petstore/kotlin-uppercase-enum/pom.xml samples/client/petstore/kotlin-uppercase-enum/pom.xml diff --git a/samples/client/petstore/kotlin-uppercase-enum/.openapi-generator/VERSION b/samples/client/petstore/kotlin-uppercase-enum/.openapi-generator/VERSION index c3a2c7076fa..58592f031f6 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/.openapi-generator/VERSION +++ b/samples/client/petstore/kotlin-uppercase-enum/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.0-SNAPSHOT \ No newline at end of file +4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/kotlin-uppercase-enum/build.gradle b/samples/client/petstore/kotlin-uppercase-enum/build.gradle index c09f7912cfe..ed72aa19d9e 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/build.gradle +++ b/samples/client/petstore/kotlin-uppercase-enum/build.gradle @@ -7,7 +7,7 @@ wrapper { } buildscript { - ext.kotlin_version = '1.3.41' + ext.kotlin_version = '1.3.61' repositories { mavenCentral() @@ -30,8 +30,8 @@ test { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - compile "com.squareup.moshi:moshi-kotlin:1.8.0" - compile "com.squareup.moshi:moshi-adapters:1.8.0" - compile "com.squareup.okhttp3:okhttp:4.0.1" - testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0" + compile "com.squareup.moshi:moshi-kotlin:1.9.2" + compile "com.squareup.moshi:moshi-adapters:1.9.2" + compile "com.squareup.okhttp3:okhttp:4.2.2" + testCompile "io.kotlintest:kotlintest-runner-junit5:3.1.0" } 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 dcd526a91c3..8ed4de2768f 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 @@ -31,11 +31,15 @@ class EnumApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl * Get enums * * @return PetEnum + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response */ @Suppress("UNCHECKED_CAST") + @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun getEnum() : PetEnum { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -43,17 +47,23 @@ class EnumApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl query = localVariableQuery, headers = localVariableHeaders ) - val response = request( + val localVarResponse = request( localVariableConfig, localVariableBody ) - return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as PetEnum + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as PetEnum ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") - ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") - ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + } } } diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..ef7a8f1e1a6 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,12 +1,12 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," "tsv" -> "\t" - "pipes" -> "|" - "ssv" -> " " + "pipe" -> "|" + "space" -> " " else -> "" } 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 4ba5be35baa..d1d58ffd0e9 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 @@ -1,5 +1,6 @@ package org.openapitools.client.infrastructure +import okhttp3.Credentials import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.RequestBody.Companion.asRequestBody @@ -107,7 +108,7 @@ open class ApiClient(val baseUrl: String) { val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase() val request = when (requestConfig.method) { - RequestMethod.DELETE -> Request.Builder().url(url).delete() + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType)) RequestMethod.GET -> Request.Builder().url(url) RequestMethod.HEAD -> Request.Builder().url(url).head() RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType)) @@ -150,4 +151,8 @@ open class ApiClient(val baseUrl: String) { ) } } + + protected inline fun parseDateToQueryString(value : T): String { + return value.toString() + } } diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt index 617ac3fe906..ff5e2a81ee8 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt @@ -9,4 +9,4 @@ class ByteArrayAdapter { @FromJson fun fromJson(data: String): ByteArray = data.toByteArray() -} \ No newline at end of file +} diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 2f3b0157ba7..41f529a5f36 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,38 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException : RuntimeException { - - /** - * Constructs an [ClientException] with no detail message. - */ - constructor() : super() - - /** - * Constructs an [ClientException] with the specified detail message. - - * @param message the detail message. - */ - constructor(message: kotlin.String) : super(message) +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException : RuntimeException { - - /** - * Constructs an [ServerException] with no detail message. - */ - constructor() : super() - - /** - * Constructs an [ServerException] with the specified detail message. - - * @param message the detail message. - */ - constructor(message: kotlin.String) : super(message) +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt new file mode 100644 index 00000000000..87437871a31 --- /dev/null +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter + +class OffsetDateTimeAdapter { + @ToJson + fun toJson(value: OffsetDateTime): String { + return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value) + } + + @FromJson + fun fromJson(value: String): OffsetDateTime { + return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME) + } + +} diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt index 934962ec6b5..69b562becb0 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt @@ -20,4 +20,4 @@ val Response.isClientError : Boolean get() = this.code in 400..499 /** * Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code */ -val Response.isServerError : Boolean get() = this.code in 500..999 \ No newline at end of file +val Response.isServerError : Boolean get() = this.code in 500..999 diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 7c5a353e0f7..697559b2ec1 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -7,12 +7,17 @@ import java.util.Date object Serializer { @JvmStatic - val moshi: Moshi = Moshi.Builder() + val moshiBuilder: Moshi.Builder = Moshi.Builder() .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) + .add(OffsetDateTimeAdapter()) .add(LocalDateTimeAdapter()) .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) .add(KotlinJsonAdapterFactory()) - .build() + + @JvmStatic + val moshi: Moshi by lazy { + moshiBuilder.build() + } }