From 9133d3f641c5de80c4d602fa8e868750617acad5 Mon Sep 17 00:00:00 2001 From: Kevin Stieglitz Date: Fri, 2 Apr 2021 00:05:23 +0200 Subject: [PATCH 1/3] use moshi polymorphic support --- .../codegen/languages/KotlinClientCodegen.java | 15 +++++++-------- .../resources/kotlin-client/build.gradle.mustache | 10 +++++++--- .../resources/kotlin-client/data_class.mustache | 2 +- .../kotlin-client/interface_opt_var.mustache | 4 +--- .../infrastructure/Serializer.kt.mustache | 10 +++++++++- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index 72646d58cd7a..0ceba7756097 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -20,14 +20,7 @@ import static java.util.Collections.sort; import org.apache.commons.lang3.StringUtils; -import org.openapitools.codegen.CliOption; -import org.openapitools.codegen.CodegenConstants; -import org.openapitools.codegen.CodegenModel; -import org.openapitools.codegen.CodegenOperation; -import org.openapitools.codegen.CodegenParameter; -import org.openapitools.codegen.CodegenProperty; -import org.openapitools.codegen.CodegenType; -import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.*; import org.openapitools.codegen.meta.features.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,6 +55,7 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { public static final String COLLECTION_TYPE = "collectionType"; protected static final String VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal"; + protected static final String VENDOR_EXTENSION_DISCRIMINATOR_BASE_NAME_LITERAL = "x-base-name-discriminator-literal"; protected String dateLibrary = DateLibrary.JAVA8.value; protected String requestDateConverter = RequestDateConverter.TO_JSON.value; @@ -618,6 +612,11 @@ public Map postProcessModels(Map objs) { for (CodegenProperty var : vars) { var.vendorExtensions.put(VENDOR_EXTENSION_BASE_NAME_LITERAL, var.baseName.replace("$", "\\$")); } + + CodegenDiscriminator discriminator = cm.getDiscriminator(); + if(discriminator != null) { + cm.vendorExtensions.put(VENDOR_EXTENSION_DISCRIMINATOR_BASE_NAME_LITERAL, discriminator.getPropertyBaseName().replace("$", "\\$")); + } } return objects; 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 1f58112db538..ae0eab921c19 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 @@ -20,6 +20,9 @@ buildscript { {{#useRxJava3}} ext.rxJava3Version = '3.0.10' {{/useRxJava3}} + {{#moshi}} + ext.moshiVersion = '1.11.0' + {{/moshi}} repositories { maven { url "https://repo1.maven.org/maven2" } @@ -56,12 +59,13 @@ dependencies { {{#moshi}} {{^moshiCodeGen}} compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - compile "com.squareup.moshi:moshi-kotlin:1.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" {{/moshiCodeGen}} {{#moshiCodeGen}} - compile "com.squareup.moshi:moshi:1.11.0" - kapt "com.squareup.moshi:moshi-kotlin-codegen:1.11.0" + compile "com.squareup.moshi:moshi:$moshiVersion" + kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion" {{/moshiCodeGen}} + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" {{/moshi}} {{#gson}} compile "com.google.code.gson:gson:2.8.6" diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache index 117cdef8fd79..bffffc8db959 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache @@ -45,7 +45,7 @@ import java.io.Serializable {{#parcelizeModels}} @Parcelize {{/parcelizeModels}} -{{#multiplatform}}@Serializable{{/multiplatform}}{{#kotlinx_serialization}}{{#serializableModel}}@KSerializable{{/serializableModel}}{{^serializableModel}}@Serializable{{/serializableModel}}{{/kotlinx_serialization}}{{#moshi}}{{#moshiCodeGen}}@JsonClass(generateAdapter = true){{/moshiCodeGen}}{{/moshi}}{{#jackson}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{/jackson}} +{{#multiplatform}}@Serializable{{/multiplatform}}{{#kotlinx_serialization}}{{#serializableModel}}@KSerializable{{/serializableModel}}{{^serializableModel}}@Serializable{{/serializableModel}}{{/kotlinx_serialization}}{{#moshi}}{{^discriminator}}{{#moshiCodeGen}}@JsonClass(generateAdapter = true){{/moshiCodeGen}}{{/discriminator}}{{/moshi}}{{#jackson}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{/jackson}} {{#isDeprecated}} @Deprecated(message = "This schema is deprecated.") {{/isDeprecated}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache index 6d23fb240a0c..9b5ea02923b5 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache @@ -2,9 +2,7 @@ /* {{{description}}} */ {{/description}} {{^multiplatform}} - {{#moshi}} - @Json(name = "{{{vendorExtensions.x-base-name-literal}}}") - {{/moshi}} + {{#moshi}}{{^discriminator}}@Json(name = "{{{vendorExtensions.x-base-name-literal}}}"){{/discriminator}}{{/moshi}} {{#gson}} @get:SerializedName("{{{vendorExtensions.x-base-name-literal}}}") {{/gson}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache index beef3fc2bf38..d34c0542e73d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache @@ -2,6 +2,7 @@ package {{packageName}}.infrastructure {{#moshi}} import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory {{^moshiCodeGen}} import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory {{/moshiCodeGen}} @@ -51,6 +52,8 @@ import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicLong {{/kotlinx_serialization}} +{{#moshi}}import {{modelPackage}}.*{{/moshi}} + {{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer { {{#moshi}} @JvmStatic @@ -60,6 +63,11 @@ import java.util.concurrent.atomic.AtomicLong .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + {{#models}}{{#model}}{{#discriminator}}.add(PolymorphicJsonAdapterFactory.of({{classname}}::class.java, "{{{vendorExtensions.x-base-name-discriminator-literal}}}") + {{#mappedModels}} + .withSubtype({{modelName}}::class.java, "{{mappingName}}") + {{/mappedModels}} + ){{/discriminator}}{{/model}}{{/models}} {{^moshiCodeGen}} .add(KotlinJsonAdapterFactory()) {{/moshiCodeGen}} @@ -78,7 +86,7 @@ import java.util.concurrent.atomic.AtomicLong .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter()) .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter()) .registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter()) - + @JvmStatic val gson: Gson by lazy { gsonBuilder.create() From 498086c8fb92abc3a4c4279a1301ddd9e6b25cdc Mon Sep 17 00:00:00 2001 From: Kevin Stieglitz Date: Fri, 2 Apr 2021 00:40:41 +0200 Subject: [PATCH 2/3] add samples --- .../org/openapitools/client/infrastructure/Serializer.kt | 2 +- .../client/petstore/kotlin-json-request-string/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ .../org/openapitools/client/infrastructure/Serializer.kt | 2 +- samples/client/petstore/kotlin-moshi-codegen/build.gradle | 6 ++++-- .../org/openapitools/client/infrastructure/Serializer.kt | 2 ++ samples/client/petstore/kotlin-nonpublic/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-nullable/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-okhttp3/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-retrofit2-rx3/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-retrofit2/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-string/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-threetenbp/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin-uppercase-enum/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ samples/client/petstore/kotlin/build.gradle | 4 +++- .../org/openapitools/client/infrastructure/Serializer.kt | 3 +++ 24 files changed, 68 insertions(+), 14 deletions(-) diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index b80e0390de2d..c05c85ca3593 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -15,7 +15,7 @@ object Serializer { .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter()) .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter()) .registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter()) - + @JvmStatic val gson: Gson by lazy { gsonBuilder.create() diff --git a/samples/client/petstore/kotlin-json-request-string/build.gradle b/samples/client/petstore/kotlin-json-request-string/build.gradle index 60e5056e0316..34d16649ec0e 100644 --- a/samples/client/petstore/kotlin-json-request-string/build.gradle +++ b/samples/client/petstore/kotlin-json-request-string/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 3d0a6c32566a..d0e9c2128050 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index b80e0390de2d..c05c85ca3593 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -15,7 +15,7 @@ object Serializer { .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter()) .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter()) .registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter()) - + @JvmStatic val gson: Gson by lazy { gsonBuilder.create() diff --git a/samples/client/petstore/kotlin-moshi-codegen/build.gradle b/samples/client/petstore/kotlin-moshi-codegen/build.gradle index 5e86b0b1a362..1fc6265e462a 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/build.gradle +++ b/samples/client/petstore/kotlin-moshi-codegen/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,8 +31,9 @@ test { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - compile "com.squareup.moshi:moshi:1.11.0" - kapt "com.squareup.moshi:moshi-kotlin-codegen:1.11.0" + compile "com.squareup.moshi:moshi:$moshiVersion" + kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 1ac7a1908fa6..310f9b27cc4d 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,7 +1,9 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic diff --git a/samples/client/petstore/kotlin-nonpublic/build.gradle b/samples/client/petstore/kotlin-nonpublic/build.gradle index 60e5056e0316..34d16649ec0e 100644 --- a/samples/client/petstore/kotlin-nonpublic/build.gradle +++ b/samples/client/petstore/kotlin-nonpublic/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 54e21400c43f..f208de5fc317 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* internal object Serializer { @JvmStatic @@ -12,6 +14,7 @@ internal object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-nullable/build.gradle b/samples/client/petstore/kotlin-nullable/build.gradle index 60e5056e0316..34d16649ec0e 100644 --- a/samples/client/petstore/kotlin-nullable/build.gradle +++ b/samples/client/petstore/kotlin-nullable/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 3d0a6c32566a..d0e9c2128050 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-okhttp3/build.gradle b/samples/client/petstore/kotlin-okhttp3/build.gradle index 1da4409df35f..6bdf65f4c7e1 100644 --- a/samples/client/petstore/kotlin-okhttp3/build.gradle +++ b/samples/client/petstore/kotlin-okhttp3/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:3.12.13" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 3d0a6c32566a..d0e9c2128050 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle b/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle index b55dfb35245f..f9da2bd483f0 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle +++ b/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle @@ -10,6 +10,7 @@ buildscript { ext.kotlin_version = '1.4.30' ext.retrofitVersion = '2.7.2' ext.rxJava3Version = '3.0.10' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -32,7 +33,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.0" compile "com.squareup.okhttp3:logging-interceptor:4.9.0" compile "io.reactivex.rxjava3:rxjava:$rxJava3Version" diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 3d0a6c32566a..d0e9c2128050 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-retrofit2/build.gradle b/samples/client/petstore/kotlin-retrofit2/build.gradle index 109eb2ca069f..68dacc2360a7 100644 --- a/samples/client/petstore/kotlin-retrofit2/build.gradle +++ b/samples/client/petstore/kotlin-retrofit2/build.gradle @@ -9,6 +9,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' ext.retrofitVersion = '2.7.2' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -31,7 +32,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.0" compile "com.squareup.okhttp3:logging-interceptor:4.9.0" compile "com.squareup.retrofit2:retrofit:$retrofitVersion" diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 3d0a6c32566a..d0e9c2128050 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-string/build.gradle b/samples/client/petstore/kotlin-string/build.gradle index 60e5056e0316..34d16649ec0e 100644 --- a/samples/client/petstore/kotlin-string/build.gradle +++ b/samples/client/petstore/kotlin-string/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } 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 3d0a6c32566a..d0e9c2128050 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,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-threetenbp/build.gradle b/samples/client/petstore/kotlin-threetenbp/build.gradle index 87605daa9d22..9623adba5f99 100644 --- a/samples/client/petstore/kotlin-threetenbp/build.gradle +++ b/samples/client/petstore/kotlin-threetenbp/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" compile "org.threeten:threetenbp:1.5.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" 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 3d0a6c32566a..d0e9c2128050 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,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin-uppercase-enum/build.gradle b/samples/client/petstore/kotlin-uppercase-enum/build.gradle index 60e5056e0316..34d16649ec0e 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/build.gradle +++ b/samples/client/petstore/kotlin-uppercase-enum/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } 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 3d0a6c32566a..d0e9c2128050 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 @@ -1,8 +1,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) diff --git a/samples/client/petstore/kotlin/build.gradle b/samples/client/petstore/kotlin/build.gradle index 60e5056e0316..34d16649ec0e 100644 --- a/samples/client/petstore/kotlin/build.gradle +++ b/samples/client/petstore/kotlin/build.gradle @@ -8,6 +8,7 @@ wrapper { buildscript { ext.kotlin_version = '1.4.30' + ext.moshiVersion = '1.11.0' repositories { maven { url "https://repo1.maven.org/maven2" } @@ -30,7 +31,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.11.0" + compile "com.squareup.moshi:moshi-kotlin:$moshiVersion" + compile "com.squareup.moshi:moshi-adapters:$moshiVersion" compile "com.squareup.okhttp3:okhttp:4.9.0" testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2" } 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 3d0a6c32566a..d0e9c2128050 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,10 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date +import org.openapitools.client.models.* object Serializer { @JvmStatic @@ -12,6 +14,7 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) From 92e1202b11c0f6518177519f74684b5358909f83 Mon Sep 17 00:00:00 2001 From: Kevin Stieglitz Date: Thu, 29 Apr 2021 21:26:16 +0200 Subject: [PATCH 3/3] implement review notes --- .../kotlin-client/interface_opt_var.mustache | 4 +++- .../infrastructure/Serializer.kt.mustache | 14 ++++++++------ .../client/infrastructure/Serializer.kt | 1 + .../client/infrastructure/Serializer.kt | 1 + .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 1 + .../client/infrastructure/Serializer.kt | 2 ++ .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 1 + .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 5 +++-- .../client/infrastructure/Serializer.kt | 5 +++-- 16 files changed, 44 insertions(+), 25 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache index 9b5ea02923b5..298d88ddea04 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache @@ -2,7 +2,9 @@ /* {{{description}}} */ {{/description}} {{^multiplatform}} - {{#moshi}}{{^discriminator}}@Json(name = "{{{vendorExtensions.x-base-name-literal}}}"){{/discriminator}}{{/moshi}} + {{#moshi}} + {{^discriminator}}@Json(name = "{{{vendorExtensions.x-base-name-literal}}}"){{/discriminator}} + {{/moshi}} {{#gson}} @get:SerializedName("{{{vendorExtensions.x-base-name-literal}}}") {{/gson}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache index d34c0542e73d..b517936da1e9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache @@ -52,7 +52,9 @@ import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicLong {{/kotlinx_serialization}} -{{#moshi}}import {{modelPackage}}.*{{/moshi}} +{{#moshi}} +import {{modelPackage}}.* +{{/moshi}} {{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer { {{#moshi}} @@ -63,16 +65,16 @@ import java.util.concurrent.atomic.AtomicLong .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) + .add(BigDecimalAdapter()) + .add(BigIntegerAdapter()) + {{^moshiCodeGen}} + .add(KotlinJsonAdapterFactory()) + {{/moshiCodeGen}} {{#models}}{{#model}}{{#discriminator}}.add(PolymorphicJsonAdapterFactory.of({{classname}}::class.java, "{{{vendorExtensions.x-base-name-discriminator-literal}}}") {{#mappedModels}} .withSubtype({{modelName}}::class.java, "{{mappingName}}") {{/mappedModels}} ){{/discriminator}}{{/model}}{{/models}} - {{^moshiCodeGen}} - .add(KotlinJsonAdapterFactory()) - {{/moshiCodeGen}} - .add(BigDecimalAdapter()) - .add(BigIntegerAdapter()) @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index c05c85ca3593..4603b266960e 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -8,6 +8,7 @@ import java.time.OffsetDateTime import java.util.UUID import java.util.Date + object Serializer { @JvmStatic val gsonBuilder: GsonBuilder = GsonBuilder() diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index ec9314126607..20bbc3a13330 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import java.util.Date + object Serializer { @JvmStatic val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper() diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index d0e9c2128050..0bccf02ff4e1 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index c05c85ca3593..4603b266960e 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -8,6 +8,7 @@ import java.time.OffsetDateTime import java.util.UUID import java.util.Date + object Serializer { @JvmStatic val gsonBuilder: GsonBuilder = GsonBuilder() diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 310f9b27cc4d..6c52e5601607 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -3,6 +3,7 @@ package org.openapitools.client.infrastructure import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -15,6 +16,7 @@ object Serializer { .add(ByteArrayAdapter()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index f208de5fc317..de8a4ce21174 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* internal object Serializer { @@ -14,10 +15,10 @@ internal object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index d0e9c2128050..0bccf02ff4e1 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index d0e9c2128050..0bccf02ff4e1 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 624053c30742..35b4d1ce41d6 100644 --- a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -15,6 +15,7 @@ import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicLong + object Serializer { @JvmStatic val kotlinSerializationAdapters = SerializersModule { diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index d0e9c2128050..0bccf02ff4e1 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index d0e9c2128050..0bccf02ff4e1 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { 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 d0e9c2128050..0bccf02ff4e1 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 @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { 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 d0e9c2128050..0bccf02ff4e1 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 @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy { 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 d0e9c2128050..0bccf02ff4e1 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 @@ -4,6 +4,7 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import java.util.Date + import org.openapitools.client.models.* object Serializer { @@ -14,10 +15,10 @@ object Serializer { .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) - - .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) + .add(KotlinJsonAdapterFactory()) + @JvmStatic val moshi: Moshi by lazy {