From 1ddccc0e970025097390bc4676a9033cf273aa45 Mon Sep 17 00:00:00 2001 From: Vincent Devos Date: Mon, 27 May 2019 14:54:50 +0200 Subject: [PATCH] [KOTLIN client] fix Moshi (Serializer/Deserializer) duplicated --- .../resources/kotlin-client/build.gradle.mustache | 8 +++++--- .../infrastructure/ApiClient.kt.mustache | 13 +------------ .../infrastructure/Serializer.kt.mustache | 4 ++-- samples/client/petstore/kotlin-string/build.gradle | 7 +++---- .../openapitools/client/infrastructure/ApiClient.kt | 13 +------------ .../client/infrastructure/Serializer.kt | 4 ++-- .../client/petstore/kotlin-threetenbp/build.gradle | 6 +++--- .../openapitools/client/infrastructure/ApiClient.kt | 13 +------------ .../client/infrastructure/Serializer.kt | 4 ++-- samples/client/petstore/kotlin/build.gradle | 7 +++---- .../openapitools/client/infrastructure/ApiClient.kt | 13 +------------ .../client/infrastructure/Serializer.kt | 4 ++-- 12 files changed, 26 insertions(+), 70 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache index 0ab36cb77470..6254c44ad9df 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache @@ -30,9 +30,11 @@ 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.5.0" - compile "com.squareup.moshi:moshi-adapters:1.5.0" - compile "com.squareup.okhttp3:okhttp:3.14.0" + compile "com.squareup.moshi:moshi-kotlin:1.8.0" + compile "com.squareup.moshi:moshi-adapters:1.8.0" + compile "com.squareup.okhttp3:okhttp:3.14.2" + {{#threetenbp}} compile "org.threeten:threetenbp:1.3.8" + {{/threetenbp}} testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0" } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache index 8d147371bcce..5a6872871ab4 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache @@ -1,8 +1,5 @@ package {{packageName}}.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory -import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.MediaType @@ -11,7 +8,6 @@ import okhttp3.HttpUrl import okhttp3.ResponseBody import okhttp3.Request import java.io.File -import java.util.Date open class ApiClient(val baseUrl: String) { companion object { @@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) { return null } return when(mediaType) { - JsonMediaType -> Moshi.Builder() - .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) - .add(LocalDateTimeAdapter()) - .add(LocalDateAdapter()) - .add(UUIDAdapter()) - .add(ByteArrayAdapter()) - .add(KotlinJsonAdapterFactory()) - .build().adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) else -> TODO("responseBody currently only supports JSON body.") } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/Serializer.kt.mustache index 7698d9ca0849..b370c468c615 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/Serializer.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/Serializer.kt.mustache @@ -1,8 +1,8 @@ package {{packageName}}.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter +import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date object Serializer { diff --git a/samples/client/petstore/kotlin-string/build.gradle b/samples/client/petstore/kotlin-string/build.gradle index 07bdfbe04d0e..2f5e3642794f 100644 --- a/samples/client/petstore/kotlin-string/build.gradle +++ b/samples/client/petstore/kotlin-string/build.gradle @@ -30,9 +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.5.0" - compile "com.squareup.moshi:moshi-adapters:1.5.0" - compile "com.squareup.okhttp3:okhttp:3.14.0" - compile "org.threeten:threetenbp:1.3.8" + compile "com.squareup.moshi:moshi-kotlin:1.8.0" + compile "com.squareup.moshi:moshi-adapters:1.8.0" + compile "com.squareup.okhttp3:okhttp:3.14.2" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0" } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a1079181cf08..c9107fcb0857 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 @@ -1,8 +1,5 @@ package org.openapitools.client.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory -import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.MediaType @@ -11,7 +8,6 @@ import okhttp3.HttpUrl import okhttp3.ResponseBody import okhttp3.Request import java.io.File -import java.util.Date open class ApiClient(val baseUrl: String) { companion object { @@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) { return null } return when(mediaType) { - JsonMediaType -> Moshi.Builder() - .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) - .add(LocalDateTimeAdapter()) - .add(LocalDateAdapter()) - .add(UUIDAdapter()) - .add(ByteArrayAdapter()) - .add(KotlinJsonAdapterFactory()) - .build().adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) else -> TODO("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index e3463f0e3c18..7c5a353e0f7f 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,8 @@ package org.openapitools.client.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter +import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date object Serializer { diff --git a/samples/client/petstore/kotlin-threetenbp/build.gradle b/samples/client/petstore/kotlin-threetenbp/build.gradle index 07bdfbe04d0e..334389dc6e36 100644 --- a/samples/client/petstore/kotlin-threetenbp/build.gradle +++ b/samples/client/petstore/kotlin-threetenbp/build.gradle @@ -30,9 +30,9 @@ 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.5.0" - compile "com.squareup.moshi:moshi-adapters:1.5.0" - compile "com.squareup.okhttp3:okhttp:3.14.0" + compile "com.squareup.moshi:moshi-kotlin:1.8.0" + compile "com.squareup.moshi:moshi-adapters:1.8.0" + compile "com.squareup.okhttp3:okhttp:3.14.2" compile "org.threeten:threetenbp:1.3.8" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0" } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a1079181cf08..c9107fcb0857 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 @@ -1,8 +1,5 @@ package org.openapitools.client.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory -import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.MediaType @@ -11,7 +8,6 @@ import okhttp3.HttpUrl import okhttp3.ResponseBody import okhttp3.Request import java.io.File -import java.util.Date open class ApiClient(val baseUrl: String) { companion object { @@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) { return null } return when(mediaType) { - JsonMediaType -> Moshi.Builder() - .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) - .add(LocalDateTimeAdapter()) - .add(LocalDateAdapter()) - .add(UUIDAdapter()) - .add(ByteArrayAdapter()) - .add(KotlinJsonAdapterFactory()) - .build().adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) else -> TODO("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index e3463f0e3c18..7c5a353e0f7f 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,8 @@ package org.openapitools.client.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter +import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date object Serializer { diff --git a/samples/client/petstore/kotlin/build.gradle b/samples/client/petstore/kotlin/build.gradle index 07bdfbe04d0e..2f5e3642794f 100644 --- a/samples/client/petstore/kotlin/build.gradle +++ b/samples/client/petstore/kotlin/build.gradle @@ -30,9 +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.5.0" - compile "com.squareup.moshi:moshi-adapters:1.5.0" - compile "com.squareup.okhttp3:okhttp:3.14.0" - compile "org.threeten:threetenbp:1.3.8" + compile "com.squareup.moshi:moshi-kotlin:1.8.0" + compile "com.squareup.moshi:moshi-adapters:1.8.0" + compile "com.squareup.okhttp3:okhttp:3.14.2" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0" } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a1079181cf08..c9107fcb0857 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 @@ -1,8 +1,5 @@ package org.openapitools.client.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory -import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.MediaType @@ -11,7 +8,6 @@ import okhttp3.HttpUrl import okhttp3.ResponseBody import okhttp3.Request import java.io.File -import java.util.Date open class ApiClient(val baseUrl: String) { companion object { @@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) { return null } return when(mediaType) { - JsonMediaType -> Moshi.Builder() - .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) - .add(LocalDateTimeAdapter()) - .add(LocalDateAdapter()) - .add(UUIDAdapter()) - .add(ByteArrayAdapter()) - .add(KotlinJsonAdapterFactory()) - .build().adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) else -> TODO("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index e3463f0e3c18..7c5a353e0f7f 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,8 @@ package org.openapitools.client.infrastructure -import com.squareup.moshi.KotlinJsonAdapterFactory import com.squareup.moshi.Moshi -import com.squareup.moshi.Rfc3339DateJsonAdapter +import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date object Serializer {