From 7eb0670665379e8613f304581c9f4efb5fb232ee Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Wed, 18 Dec 2019 15:46:10 +0000
Subject: [PATCH 1/8] [kotlin] add OffsetDateTime support

---
 .../languages/AbstractKotlinCodegen.java      |  6 +-
 .../languages/KotlinClientCodegen.java        | 55 +++++++++-------
 .../OffsetDateTimeAdapter.kt.mustache         | 63 +++++++++++++++++++
 .../jvm/infrastructure/Serializer.kt.mustache |  2 +
 .../OffsetDateTimeAdapter.kt.mustache         | 63 +++++++++++++++++++
 .../infrastructure/Serializer.kt.mustache     |  6 ++
 .../kotlin/KotlinClientCodegenModelTest.java  | 52 ++++++++++++++-
 .../client/petstore/kotlin-gson/docs/Order.md |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 35 +++++++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../kotlin-json-request-date/docs/Order.md    |  2 +-
 .../kotlin-json-request-date/docs/PetApi.md   |  4 +-
 .../org/openapitools/client/apis/PetApi.kt    |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../kotlin-moshi-codegen/docs/Order.md        |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../petstore/kotlin-nonpublic/docs/Order.md   |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../petstore/kotlin-nullable/docs/Order.md    |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../petstore/kotlin-okhttp3/docs/Order.md     |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../petstore/kotlin-retrofit2/docs/Order.md   |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../petstore/kotlin-threetenbp/docs/Order.md  |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 samples/client/petstore/kotlin/docs/Order.md  |  2 +-
 .../infrastructure/OffsetDateTimeAdapter.kt   | 19 ++++++
 .../client/infrastructure/Serializer.kt       |  1 +
 .../org/openapitools/client/models/Order.kt   |  2 +-
 47 files changed, 458 insertions(+), 47 deletions(-)
 create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/OffsetDateTimeAdapter.kt.mustache
 create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/OffsetDateTimeAdapter.kt.mustache
 create mode 100644 samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
 create mode 100644 samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
index 606e0564c44..50bdfdb0af2 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
@@ -182,7 +182,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
         typeMapping.put("double", "kotlin.Double");
         typeMapping.put("ByteArray", "kotlin.ByteArray");
         typeMapping.put("number", "java.math.BigDecimal");
-        typeMapping.put("date-time", "java.time.LocalDateTime");
+        typeMapping.put("date-time", "java.time.OffsetDateTime");
         typeMapping.put("date", "java.time.LocalDate");
         typeMapping.put("file", "java.io.File");
         typeMapping.put("array", "kotlin.Array");
@@ -192,7 +192,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
         typeMapping.put("object", "kotlin.Any");
         typeMapping.put("binary", "kotlin.Array<kotlin.Byte>");
         typeMapping.put("Date", "java.time.LocalDate");
-        typeMapping.put("DateTime", "java.time.LocalDateTime");
+        typeMapping.put("DateTime", "java.time.OffsetDateTime");
 
         instantiationTypes.put("array", "kotlin.arrayOf");
         instantiationTypes.put("list", "kotlin.arrayOf");
@@ -205,7 +205,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
         importMapping.put("File", "java.io.File");
         importMapping.put("Date", "java.util.Date");
         importMapping.put("Timestamp", "java.sql.Timestamp");
-        importMapping.put("DateTime", "java.time.LocalDateTime");
+        importMapping.put("DateTime", "java.time.OffsetDateTime");
         importMapping.put("LocalDateTime", "java.time.LocalDateTime");
         importMapping.put("LocalDate", "java.time.LocalDate");
         importMapping.put("LocalTime", "java.time.LocalTime");
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 b1407a71f32..92e596520dd 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
@@ -55,7 +55,9 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
     public enum DateLibrary {
         STRING("string"),
         THREETENBP("threetenbp"),
-        JAVA8("java8");
+        THREETENBP_LOCALDATETIME("threetenbp-localdatetime"),
+        JAVA8("java8"),
+        JAVA8_LOCALDATETIME("java8-localdatetime");
 
         public final String value;
 
@@ -110,9 +112,11 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
 
         CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
         Map<String, String> dateOptions = new HashMap<>();
-        dateOptions.put(DateLibrary.THREETENBP.value, "Threetenbp (jvm only)");
+        dateOptions.put(DateLibrary.THREETENBP.value, "Threetenbp - Backport of JSR310 (jvm only, preferred for jdk < 1.8)");
+        dateOptions.put(DateLibrary.THREETENBP_LOCALDATETIME.value, "Threetenbp - Backport of JSR310 (jvm only, for legacy app only)");
         dateOptions.put(DateLibrary.STRING.value, "String");
-        dateOptions.put(DateLibrary.JAVA8.value, "Java 8 native JSR310 (jvm only)");
+        dateOptions.put(DateLibrary.JAVA8.value, "Java 8 native JSR310 (jvm only, preferred for jdk 1.8+)");
+        dateOptions.put(DateLibrary.JAVA8_LOCALDATETIME.value, "Java 8 native JSR310 (jvm only, for legacy app only)");
         dateLibrary.setEnum(dateOptions);
         dateLibrary.setDefault(this.dateLibrary);
         cliOptions.add(dateLibrary);
@@ -221,19 +225,12 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
     }
 
     private void processDateLibrary() {
-        DateLibrary dateLibraryEnum = DateLibrary.valueOf(dateLibrary.toUpperCase(Locale.ROOT));
-        switch (dateLibraryEnum) {
-            case THREETENBP:
-                processThreeTeBpDate();
-                break;
-            case STRING:
-                processStringDate();
-                break;
-            case JAVA8:
-                processJava8Date();
-                break;
-            default:
-                break;
+        if (DateLibrary.THREETENBP.value.equals(dateLibrary) || DateLibrary.THREETENBP_LOCALDATETIME.value.equals(dateLibrary)) {
+            processThreeTeBpDate(dateLibrary);
+        } else if (DateLibrary.STRING.value.equals(dateLibrary)) {
+            processStringDate();
+        } else if (DateLibrary.JAVA8.value.equals(dateLibrary) || DateLibrary.JAVA8_LOCALDATETIME.value.equals(dateLibrary)) {
+            processJava8Date(dateLibrary);
         }
     }
 
@@ -245,14 +242,21 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
         }
     }
 
-    private void processThreeTeBpDate() {
+    private void processThreeTeBpDate(String dateLibrary) {
         additionalProperties.put(DateLibrary.THREETENBP.value, true);
         typeMapping.put("date", "LocalDate");
-        typeMapping.put("DateTime", "LocalDateTime");
         importMapping.put("LocalDate", "org.threeten.bp.LocalDate");
-        importMapping.put("LocalDateTime", "org.threeten.bp.LocalDateTime");
         defaultIncludes.add("org.threeten.bp.LocalDate");
-        defaultIncludes.add("org.threeten.bp.LocalDateTime");
+
+        if (dateLibrary.equals(DateLibrary.THREETENBP.value)) {
+            typeMapping.put("DateTime", "OffsetDateTime");
+            importMapping.put("OffsetDateTime", "org.threeten.bp.OffsetDateTime");
+            defaultIncludes.add("org.threeten.bp.OffsetDateTime");
+        } else if (dateLibrary.equals(DateLibrary.THREETENBP_LOCALDATETIME.value)) {
+            typeMapping.put("DateTime", "LocalDateTime");
+            importMapping.put("LocalDateTime", "org.threeten.bp.LocalDateTime");
+            defaultIncludes.add("org.threeten.bp.LocalDateTime");
+        }
     }
 
     private void processStringDate() {
@@ -262,8 +266,16 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
         typeMapping.put("DateTime", "kotlin.String");
     }
 
-    private void processJava8Date() {
+    private void processJava8Date(String dateLibrary) {
         additionalProperties.put(DateLibrary.JAVA8.value, true);
+
+        if (dateLibrary.equals(DateLibrary.JAVA8.value)) {
+            typeMapping.put("DateTime", "OffsetDateTime");
+            importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
+        } else if (dateLibrary.equals(DateLibrary.JAVA8_LOCALDATETIME.value)) {
+            typeMapping.put("DateTime", "LocalDateTime");
+            importMapping.put("LocalDateTime", "java.time.LocalDateTime");
+        }
     }
 
     private void processRetrofit2Library(String infrastructureFolder) {
@@ -278,6 +290,7 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
         supportingFiles.add(new SupportingFile("infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));
         supportingFiles.add(new SupportingFile("infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt"));
         supportingFiles.add(new SupportingFile("infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt"));
+        supportingFiles.add(new SupportingFile("infrastructure/OffsetDateTimeAdapter.kt.mustache", infrastructureFolder, "OffsetDateTimeAdapter.kt"));
         supportingFiles.add(new SupportingFile("infrastructure/UUIDAdapter.kt.mustache", infrastructureFolder, "UUIDAdapter.kt"));
 
         if (getSerializationLibrary() == SERIALIZATION_LIBRARY_TYPE.gson) {
diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/OffsetDateTimeAdapter.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/OffsetDateTimeAdapter.kt.mustache
new file mode 100644
index 00000000000..fbcd16447ac
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/OffsetDateTimeAdapter.kt.mustache
@@ -0,0 +1,63 @@
+package {{packageName}}.infrastructure
+
+{{#moshi}}
+import com.squareup.moshi.FromJson
+import com.squareup.moshi.ToJson
+{{/moshi}}
+{{#gson}}
+import com.google.gson.TypeAdapter
+import com.google.gson.stream.JsonReader
+import com.google.gson.stream.JsonWriter
+import com.google.gson.stream.JsonToken.NULL
+import java.io.IOException
+{{/gson}}
+{{^threetenbp}}
+import java.time.OffsetDateTime
+import java.time.format.DateTimeFormatter
+{{/threetenbp}}
+{{#threetenbp}}
+import org.threeten.bp.OffsetDateTime
+import org.threeten.bp.format.DateTimeFormatter
+{{/threetenbp}}
+
+{{#moshi}}
+{{#nonPublicApi}}internal {{/nonPublicApi}}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)
+    }
+
+}
+{{/moshi}}
+{{#gson}}
+{{#nonPublicApi}}internal {{/nonPublicApi}}class OffsetDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME) : TypeAdapter<OffsetDateTime>() {
+    @Throws(IOException::class)
+    override fun write(out: JsonWriter?, value: OffsetDateTime?) {
+        if (value == null) {
+            out?.nullValue()
+        } else {
+            out?.value(formatter.format(value))
+        }
+    }
+
+    @Throws(IOException::class)
+    override fun read(out: JsonReader?): OffsetDateTime? {
+        out ?: return null
+
+        when (out.peek()) {
+            NULL -> {
+                out.nextNull()
+                return null
+            }
+            else -> {
+                return OffsetDateTime.parse(out.nextString(), formatter)
+            }
+        }
+    }
+}
+{{/gson}}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache
index f410f059914..514a72e5c34 100644
--- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache
@@ -27,6 +27,7 @@ import java.util.Date
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
@@ -40,6 +41,7 @@ import java.util.Date
     @JvmStatic
     val gson: Gson = GsonBuilder()
         .registerTypeAdapter(Date::class.java, DateAdapter())
+        .registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter())
         .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
         .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
         .registerTypeAdapter(UUID::class.java, UUIDAdapter())
diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/OffsetDateTimeAdapter.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/OffsetDateTimeAdapter.kt.mustache
new file mode 100644
index 00000000000..fbcd16447ac
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/OffsetDateTimeAdapter.kt.mustache
@@ -0,0 +1,63 @@
+package {{packageName}}.infrastructure
+
+{{#moshi}}
+import com.squareup.moshi.FromJson
+import com.squareup.moshi.ToJson
+{{/moshi}}
+{{#gson}}
+import com.google.gson.TypeAdapter
+import com.google.gson.stream.JsonReader
+import com.google.gson.stream.JsonWriter
+import com.google.gson.stream.JsonToken.NULL
+import java.io.IOException
+{{/gson}}
+{{^threetenbp}}
+import java.time.OffsetDateTime
+import java.time.format.DateTimeFormatter
+{{/threetenbp}}
+{{#threetenbp}}
+import org.threeten.bp.OffsetDateTime
+import org.threeten.bp.format.DateTimeFormatter
+{{/threetenbp}}
+
+{{#moshi}}
+{{#nonPublicApi}}internal {{/nonPublicApi}}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)
+    }
+
+}
+{{/moshi}}
+{{#gson}}
+{{#nonPublicApi}}internal {{/nonPublicApi}}class OffsetDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME) : TypeAdapter<OffsetDateTime>() {
+    @Throws(IOException::class)
+    override fun write(out: JsonWriter?, value: OffsetDateTime?) {
+        if (value == null) {
+            out?.nullValue()
+        } else {
+            out?.value(formatter.format(value))
+        }
+    }
+
+    @Throws(IOException::class)
+    override fun read(out: JsonReader?): OffsetDateTime? {
+        out ?: return null
+
+        when (out.peek()) {
+            NULL -> {
+                out.nextNull()
+                return null
+            }
+            else -> {
+                return OffsetDateTime.parse(out.nextString(), formatter)
+            }
+        }
+    }
+}
+{{/gson}}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache
index df4c33c26d2..514a72e5c34 100644
--- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache
@@ -3,7 +3,9 @@ package {{packageName}}.infrastructure
 {{#moshi}}
 import com.squareup.moshi.Moshi
 import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
+{{^moshiCodeGen}}
 import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
+{{/moshiCodeGen}}
 {{/moshi}}
 {{#gson}}
 import com.google.gson.Gson
@@ -25,17 +27,21 @@ import java.util.Date
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
         .add(ByteArrayAdapter())
+        {{^moshiCodeGen}}
         .add(KotlinJsonAdapterFactory())
+        {{/moshiCodeGen}}
         .build()
 {{/moshi}}
 {{#gson}}
     @JvmStatic
     val gson: Gson = GsonBuilder()
         .registerTypeAdapter(Date::class.java, DateAdapter())
+        .registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter())
         .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
         .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
         .registerTypeAdapter(UUID::class.java, UUIDAdapter())
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java
index e85b79367f1..4175924d5ae 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java
@@ -100,10 +100,10 @@ public class KotlinClientCodegenModelTest {
 
         final CodegenProperty property3 = cm.vars.get(2);
         Assert.assertEquals(property3.baseName, "createdAt");
-        Assert.assertEquals(property3.dataType, "java.time.LocalDateTime");
+        Assert.assertEquals(property3.dataType, "java.time.OffsetDateTime");
         Assert.assertEquals(property3.name, "createdAt");
         Assert.assertEquals(property3.defaultValue, null);
-        Assert.assertEquals(property3.baseType, "java.time.LocalDateTime");
+        Assert.assertEquals(property3.baseType, "java.time.OffsetDateTime");
         Assert.assertFalse(property3.hasMore);
         Assert.assertFalse(property3.required);
         Assert.assertFalse(property3.isContainer);
@@ -120,6 +120,30 @@ public class KotlinClientCodegenModelTest {
         codegen.setOpenAPI(openAPI);
         final CodegenModel cm = codegen.fromModel("sample", schema);
 
+        final CodegenProperty property3 = cm.vars.get(2);
+        Assert.assertEquals(property3.baseName, "createdAt");
+        Assert.assertEquals(property3.dataType, "org.threeten.bp.OffsetDateTime");
+        Assert.assertEquals(property3.name, "createdAt");
+        Assert.assertEquals(property3.defaultValue, null);
+        Assert.assertEquals(property3.baseType, "org.threeten.bp.OffsetDateTime");
+        Assert.assertFalse(property3.hasMore);
+        Assert.assertFalse(property3.required);
+        Assert.assertFalse(property3.isContainer);
+    }
+
+    @Test(description = "convert a simple model: threetenbp-localdatetime")
+    public void selectDateLibraryAsThreetenbpLocalDateTime() {
+        final Schema schema = getSimpleSchema();
+        final KotlinClientCodegen codegen = new KotlinClientCodegen();
+        String value = KotlinClientCodegen.DateLibrary.THREETENBP_LOCALDATETIME.value;
+        Assert.assertEquals(value, "threetenbp-localdatetime");
+        codegen.setDateLibrary(KotlinClientCodegen.DateLibrary.THREETENBP_LOCALDATETIME.value);
+        codegen.processOpts();
+
+        OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
+        codegen.setOpenAPI(openAPI);
+        final CodegenModel cm = codegen.fromModel("sample", schema);
+
         final CodegenProperty property3 = cm.vars.get(2);
         Assert.assertEquals(property3.baseName, "createdAt");
         Assert.assertEquals(property3.dataType, "org.threeten.bp.LocalDateTime");
@@ -164,6 +188,30 @@ public class KotlinClientCodegenModelTest {
         codegen.setOpenAPI(openAPI);
         final CodegenModel cm = codegen.fromModel("sample", schema);
 
+        final CodegenProperty property3 = cm.vars.get(2);
+        Assert.assertEquals(property3.baseName, "createdAt");
+        Assert.assertEquals(property3.dataType, "java.time.OffsetDateTime");
+        Assert.assertEquals(property3.name, "createdAt");
+        Assert.assertEquals(property3.defaultValue, null);
+        Assert.assertEquals(property3.baseType, "java.time.OffsetDateTime");
+        Assert.assertFalse(property3.hasMore);
+        Assert.assertFalse(property3.required);
+        Assert.assertFalse(property3.isContainer);
+    }
+
+    @Test(description = "convert a simple model: date java8-localdatetime")
+    public void selectDateLibraryAsJava8LocalDateTime() {
+        final Schema schema = getSimpleSchema();
+        final KotlinClientCodegen codegen = new KotlinClientCodegen();
+        String value = KotlinClientCodegen.DateLibrary.JAVA8_LOCALDATETIME.value;
+        Assert.assertEquals(value, "java8-localdatetime");
+        codegen.setDateLibrary(KotlinClientCodegen.DateLibrary.JAVA8_LOCALDATETIME.value);
+        codegen.processOpts();
+
+        OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
+        codegen.setOpenAPI(openAPI);
+        final CodegenModel cm = codegen.fromModel("sample", schema);
+
         final CodegenProperty property3 = cm.vars.get(2);
         Assert.assertEquals(property3.baseName, "createdAt");
         Assert.assertEquals(property3.dataType, "java.time.LocalDateTime");
diff --git a/samples/client/petstore/kotlin-gson/docs/Order.md b/samples/client/petstore/kotlin-gson/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-gson/docs/Order.md
+++ b/samples/client/petstore/kotlin-gson/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..e615135c9cc
--- /dev/null
+++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
@@ -0,0 +1,35 @@
+package org.openapitools.client.infrastructure
+
+import com.google.gson.TypeAdapter
+import com.google.gson.stream.JsonReader
+import com.google.gson.stream.JsonWriter
+import com.google.gson.stream.JsonToken.NULL
+import java.io.IOException
+import java.time.OffsetDateTime
+import java.time.format.DateTimeFormatter
+
+class OffsetDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME) : TypeAdapter<OffsetDateTime>() {
+    @Throws(IOException::class)
+    override fun write(out: JsonWriter?, value: OffsetDateTime?) {
+        if (value == null) {
+            out?.nullValue()
+        } else {
+            out?.value(formatter.format(value))
+        }
+    }
+
+    @Throws(IOException::class)
+    override fun read(out: JsonReader?): OffsetDateTime? {
+        out ?: return null
+
+        when (out.peek()) {
+            NULL -> {
+                out.nextNull()
+                return null
+            }
+            else -> {
+                return OffsetDateTime.parse(out.nextString(), formatter)
+            }
+        }
+    }
+}
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 a81be094f41..628e82400e3 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
@@ -11,6 +11,7 @@ object Serializer {
     @JvmStatic
     val gson: Gson = GsonBuilder()
         .registerTypeAdapter(Date::class.java, DateAdapter())
+        .registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter())
         .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
         .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
         .registerTypeAdapter(UUID::class.java, UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/models/Order.kt
index ac55ce97d53..5a33789128b 100644
--- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -31,7 +31,7 @@ data class Order (
     @SerializedName("quantity")
     val quantity: kotlin.Int? = null,
     @SerializedName("shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @SerializedName("status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-json-request-date/docs/Order.md b/samples/client/petstore/kotlin-json-request-date/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-json-request-date/docs/Order.md
+++ b/samples/client/petstore/kotlin-json-request-date/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-json-request-date/docs/PetApi.md b/samples/client/petstore/kotlin-json-request-date/docs/PetApi.md
index f3b19f26edb..dd70fe9495d 100644
--- a/samples/client/petstore/kotlin-json-request-date/docs/PetApi.md
+++ b/samples/client/petstore/kotlin-json-request-date/docs/PetApi.md
@@ -170,7 +170,7 @@ Get all pets
 //import org.openapitools.client.models.*
 
 val apiInstance = PetApi()
-val lastUpdated : java.time.LocalDateTime = 2013-10-20T19:20:30+01:00 // java.time.LocalDateTime | When this endpoint was hit last to help indentify if the client already has the latest copy.
+val lastUpdated : java.time.OffsetDateTime = 2013-10-20T19:20:30+01:00 // java.time.OffsetDateTime | When this endpoint was hit last to help indentify if the client already has the latest copy.
 try {
     val result : kotlin.Array<Pet> = apiInstance.getAllPets(lastUpdated)
     println(result)
@@ -187,7 +187,7 @@ try {
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **lastUpdated** | **java.time.LocalDateTime**| When this endpoint was hit last to help indentify if the client already has the latest copy. | [optional]
+ **lastUpdated** | **java.time.OffsetDateTime**| When this endpoint was hit last to help indentify if the client already has the latest copy. | [optional]
 
 ### Return type
 
diff --git a/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
index 491cc838508..1784c4490ee 100644
--- a/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
+++ b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
@@ -146,7 +146,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
     */
     @Suppress("UNCHECKED_CAST")
     @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
-    fun getAllPets(lastUpdated: java.time.LocalDateTime?) : kotlin.Array<Pet> {
+    fun getAllPets(lastUpdated: java.time.OffsetDateTime?) : kotlin.Array<Pet> {
         val localVariableBody: kotlin.Any? = null
         val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, List<kotlin.String>>()
             .apply {
diff --git a/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin-json-request-date/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-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
index 7c5a353e0f7..30ccaefd4f3 100644
--- a/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
+++ b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/models/Order.kt
index bcdb149159b..6bf55feb4ea 100644
--- a/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-json-request-date/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -31,7 +31,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-moshi-codegen/docs/Order.md b/samples/client/petstore/kotlin-moshi-codegen/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-moshi-codegen/docs/Order.md
+++ b/samples/client/petstore/kotlin-moshi-codegen/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin-moshi-codegen/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-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 087015252b8..c626a6fe141 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
@@ -8,6 +8,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/models/Order.kt
index 34441ed63c5..dd01d68e3f0 100644
--- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -32,7 +32,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-nonpublic/docs/Order.md b/samples/client/petstore/kotlin-nonpublic/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-nonpublic/docs/Order.md
+++ b/samples/client/petstore/kotlin-nonpublic/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..be7703c103d
--- /dev/null
+++ b/samples/client/petstore/kotlin-nonpublic/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
+
+internal 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-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 051082f5628..5458518ad37 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
@@ -9,6 +9,7 @@ internal object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/models/Order.kt
index 23ee50a8af9..fcec740e09e 100644
--- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -31,7 +31,7 @@ internal data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-nullable/docs/Order.md b/samples/client/petstore/kotlin-nullable/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-nullable/docs/Order.md
+++ b/samples/client/petstore/kotlin-nullable/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin-nullable/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-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 7c5a353e0f7..30ccaefd4f3 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
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/models/Order.kt
index 47862cfb7b6..452a176c120 100644
--- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -32,7 +32,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-okhttp3/docs/Order.md b/samples/client/petstore/kotlin-okhttp3/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-okhttp3/docs/Order.md
+++ b/samples/client/petstore/kotlin-okhttp3/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin-okhttp3/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-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 7c5a353e0f7..30ccaefd4f3 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
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Order.kt
index bcdb149159b..6bf55feb4ea 100644
--- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -31,7 +31,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-retrofit2/docs/Order.md b/samples/client/petstore/kotlin-retrofit2/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin-retrofit2/docs/Order.md
+++ b/samples/client/petstore/kotlin-retrofit2/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin-retrofit2/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-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 7c5a353e0f7..30ccaefd4f3 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
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/models/Order.kt
index bcdb149159b..6bf55feb4ea 100644
--- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -31,7 +31,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin-string/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-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 7c5a353e0f7..30ccaefd4f3 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
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-threetenbp/docs/Order.md b/samples/client/petstore/kotlin-threetenbp/docs/Order.md
index fb2b4ace861..776e0ddc2f0 100644
--- a/samples/client/petstore/kotlin-threetenbp/docs/Order.md
+++ b/samples/client/petstore/kotlin-threetenbp/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**org.threeten.bp.LocalDateTime**](org.threeten.bp.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**org.threeten.bp.OffsetDateTime**](org.threeten.bp.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..28b3eb3cd70
--- /dev/null
+++ b/samples/client/petstore/kotlin-threetenbp/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 org.threeten.bp.OffsetDateTime
+import org.threeten.bp.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-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 7c5a353e0f7..30ccaefd4f3 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
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/models/Order.kt
index a1e3c6e200d..cb25060ae82 100644
--- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -31,7 +31,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: org.threeten.bp.LocalDateTime? = null,
+    val shipDate: org.threeten.bp.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
diff --git a/samples/client/petstore/kotlin/docs/Order.md b/samples/client/petstore/kotlin/docs/Order.md
index ef31dbf2f4f..5112f08958d 100644
--- a/samples/client/petstore/kotlin/docs/Order.md
+++ b/samples/client/petstore/kotlin/docs/Order.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **id** | **kotlin.Long** |  |  [optional]
 **petId** | **kotlin.Long** |  |  [optional]
 **quantity** | **kotlin.Int** |  |  [optional]
-**shipDate** | [**java.time.LocalDateTime**](java.time.LocalDateTime.md) |  |  [optional]
+**shipDate** | [**java.time.OffsetDateTime**](java.time.OffsetDateTime.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | Order Status |  [optional]
 **complete** | **kotlin.Boolean** |  |  [optional]
 
diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
new file mode 100644
index 00000000000..87437871a31
--- /dev/null
+++ b/samples/client/petstore/kotlin/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/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
index 7c5a353e0f7..30ccaefd4f3 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
@@ -9,6 +9,7 @@ object Serializer {
     @JvmStatic
     val moshi: Moshi = Moshi.Builder()
         .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
+        .add(OffsetDateTimeAdapter())
         .add(LocalDateTimeAdapter())
         .add(LocalDateAdapter())
         .add(UUIDAdapter())
diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Order.kt
index 47862cfb7b6..452a176c120 100644
--- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Order.kt
+++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Order.kt
@@ -32,7 +32,7 @@ data class Order (
     @Json(name = "quantity")
     val quantity: kotlin.Int? = null,
     @Json(name = "shipDate")
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     @Json(name = "status")
     val status: Order.Status? = null,
-- 
GitLab


From 61f54fc9fb0c93f4cca61cb36b7adb22acb2809e Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Wed, 18 Dec 2019 16:11:52 +0000
Subject: [PATCH 2/8] [kotlin] serializer add missing import

---
 .../libraries/jvm/infrastructure/Serializer.kt.mustache         | 2 ++
 .../libraries/retrofit2/infrastructure/Serializer.kt.mustache   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache
index 514a72e5c34..85562d5df01 100644
--- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm/infrastructure/Serializer.kt.mustache
@@ -13,10 +13,12 @@ import com.google.gson.GsonBuilder
 {{^threetenbp}}
 import java.time.LocalDate
 import java.time.LocalDateTime
+import java.time.OffsetDateTime
 {{/threetenbp}}
 {{#threetenbp}}
 import org.threeten.bp.LocalDate
 import org.threeten.bp.LocalDateTime
+import org.threeten.bp.OffsetDateTime
 {{/threetenbp}}
 import java.util.UUID
 {{/gson}}
diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache
index 514a72e5c34..85562d5df01 100644
--- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/retrofit2/infrastructure/Serializer.kt.mustache
@@ -13,10 +13,12 @@ import com.google.gson.GsonBuilder
 {{^threetenbp}}
 import java.time.LocalDate
 import java.time.LocalDateTime
+import java.time.OffsetDateTime
 {{/threetenbp}}
 {{#threetenbp}}
 import org.threeten.bp.LocalDate
 import org.threeten.bp.LocalDateTime
+import org.threeten.bp.OffsetDateTime
 {{/threetenbp}}
 import java.util.UUID
 {{/gson}}
-- 
GitLab


From bf0f4ed3940afcbdbc8e639782b928d38171ae8f Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Wed, 18 Dec 2019 18:38:17 +0000
Subject: [PATCH 3/8] [kotlin] update pet projects and fix tests

---
 .../kotlin/org/openapitools/client/infrastructure/Serializer.kt | 1 +
 .../src/test/kotlin/org/openapitools/client/StoreApiTest.kt     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

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 628e82400e3..c15924eed76 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
@@ -4,6 +4,7 @@ import com.google.gson.Gson
 import com.google.gson.GsonBuilder
 import java.time.LocalDate
 import java.time.LocalDateTime
+import java.time.OffsetDateTime
 import java.util.UUID
 import java.util.Date
 
diff --git a/samples/client/petstore/kotlin/src/test/kotlin/org/openapitools/client/StoreApiTest.kt b/samples/client/petstore/kotlin/src/test/kotlin/org/openapitools/client/StoreApiTest.kt
index 1807e516eb0..733df971a8b 100644
--- a/samples/client/petstore/kotlin/src/test/kotlin/org/openapitools/client/StoreApiTest.kt
+++ b/samples/client/petstore/kotlin/src/test/kotlin/org/openapitools/client/StoreApiTest.kt
@@ -6,7 +6,7 @@ import org.openapitools.client.apis.PetApi
 import org.openapitools.client.apis.StoreApi
 import org.openapitools.client.models.Order
 import org.openapitools.client.models.Pet
-import java.time.LocalDateTime.now
+import java.time.OffsetDateTime.now
 
 class StoreApiTest : ShouldSpec() {
     init {
-- 
GitLab


From af0f30ae4d23ed2767e1b7e2a639dcb1e96b8695 Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Wed, 18 Dec 2019 18:43:35 +0000
Subject: [PATCH 4/8] [kotlin] update docs

---
 docs/generators/kotlin.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/docs/generators/kotlin.md b/docs/generators/kotlin.md
index 86fbf23e5d0..8f9b15e19b9 100644
--- a/docs/generators/kotlin.md
+++ b/docs/generators/kotlin.md
@@ -16,6 +16,7 @@ sidebar_label: kotlin
 |parcelizeModels|toggle &quot;@Parcelize&quot; for generated models| |null|
 |serializableModel|boolean - toggle &quot;implements Serializable&quot; for generated models| |null|
 |modelMutable|Create mutable models| |false|
-|dateLibrary|Option. Date library to use|<dl><dt>**string**</dt><dd>String</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only)</dd><dt>**threetenbp**</dt><dd>Threetenbp (jvm only)</dd><dl>|java8|
+|dateLibrary|Option. Date library to use|<dl><dt>**threetenbp-localdatetime**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, for legacy app only)</dd><dt>**string**</dt><dd>String</dd><dt>**java8-localdatetime**</dt><dd>Java 8 native JSR310 (jvm only, for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only, preferred for jdk 1.8+)</dd><dt>**threetenbp**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, preferred for jdk &lt; 1.8)</dd><dl>|java8|
 |collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd><dl>|array|
 |library|Library template (sub-template) to use|<dl><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-okhttp3**</dt><dd>Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.</dd><dt>**retrofit2**</dt><dd>Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.2.4. JSON processing: Kotlinx Serialization: 0.12.0.</dd><dl>|jvm-okhttp4|
+|requestDateConverter|JVM-Option. Defines in how to handle date-time objects that are used for a request (as query or parameter)|<dl><dt>**toJson**</dt><dd>Date formater option using a json converter.</dd><dt>**toString**</dt><dd>[DEFAULT] Use the 'toString'-method of the date-time object to retrieve the related string representation.</dd><dl>|toString|
-- 
GitLab


From a043c1ef21cbeed1bd3e19218096df0dfbad2cc7 Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Wed, 18 Dec 2019 19:36:28 +0000
Subject: [PATCH 5/8] [kotlin] update pet projects

---
 .../src/main/kotlin/org/openapitools/server/models/Order.kt     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt
index dc79ef79e70..dd392773e96 100644
--- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt
+++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt
@@ -26,7 +26,7 @@ data class Order (
     val id: kotlin.Long? = null,
     val petId: kotlin.Long? = null,
     val quantity: kotlin.Int? = null,
-    val shipDate: java.time.LocalDateTime? = null,
+    val shipDate: java.time.OffsetDateTime? = null,
     /* Order Status */
     val status: Order.Status? = null,
     val complete: kotlin.Boolean? = null
-- 
GitLab


From a2c5a9ae57f7b195abecd015ce16b1246f4407ee Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Fri, 20 Dec 2019 11:12:32 +0000
Subject: [PATCH 6/8] [kotlin] update date-time

---
 .../codegen/languages/AbstractKotlinCodegen.java            | 6 +++---
 .../openapitools/codegen/languages/KotlinClientCodegen.java | 4 ++++
 .../codegen/kotlin/KotlinClientCodegenModelTest.java        | 1 +
 .../src/main/kotlin/org/openapitools/server/models/Order.kt | 2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
index 332d3983771..ed895fd5ac1 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java
@@ -183,7 +183,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
         typeMapping.put("double", "kotlin.Double");
         typeMapping.put("ByteArray", "kotlin.ByteArray");
         typeMapping.put("number", "java.math.BigDecimal");
-        typeMapping.put("date-time", "java.time.OffsetDateTime");
+        typeMapping.put("date-time", "java.time.LocalDateTime");
         typeMapping.put("date", "java.time.LocalDate");
         typeMapping.put("file", "java.io.File");
         typeMapping.put("array", "kotlin.Array");
@@ -193,7 +193,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
         typeMapping.put("object", "kotlin.Any");
         typeMapping.put("binary", "kotlin.Array<kotlin.Byte>");
         typeMapping.put("Date", "java.time.LocalDate");
-        typeMapping.put("DateTime", "java.time.OffsetDateTime");
+        typeMapping.put("DateTime", "java.time.LocalDateTime");
 
         instantiationTypes.put("array", "kotlin.arrayOf");
         instantiationTypes.put("list", "kotlin.arrayOf");
@@ -206,7 +206,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
         importMapping.put("File", "java.io.File");
         importMapping.put("Date", "java.util.Date");
         importMapping.put("Timestamp", "java.sql.Timestamp");
-        importMapping.put("DateTime", "java.time.OffsetDateTime");
+        importMapping.put("DateTime", "java.time.LocalDateTime");
         importMapping.put("LocalDateTime", "java.time.LocalDateTime");
         importMapping.put("LocalDate", "java.time.LocalDate");
         importMapping.put("LocalTime", "java.time.LocalTime");
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 01ec5ef9868..85bffe3f058 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
@@ -250,10 +250,12 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
         defaultIncludes.add("org.threeten.bp.LocalDate");
 
         if (dateLibrary.equals(DateLibrary.THREETENBP.value)) {
+            typeMapping.put("date-time", "org.threeten.bp.OffsetDateTime");
             typeMapping.put("DateTime", "OffsetDateTime");
             importMapping.put("OffsetDateTime", "org.threeten.bp.OffsetDateTime");
             defaultIncludes.add("org.threeten.bp.OffsetDateTime");
         } else if (dateLibrary.equals(DateLibrary.THREETENBP_LOCALDATETIME.value)) {
+            typeMapping.put("date-time", "org.threeten.bp.LocalDateTime");
             typeMapping.put("DateTime", "LocalDateTime");
             importMapping.put("LocalDateTime", "org.threeten.bp.LocalDateTime");
             defaultIncludes.add("org.threeten.bp.LocalDateTime");
@@ -271,9 +273,11 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
         additionalProperties.put(DateLibrary.JAVA8.value, true);
 
         if (dateLibrary.equals(DateLibrary.JAVA8.value)) {
+            typeMapping.put("date-time", "java.time.OffsetDateTime");
             typeMapping.put("DateTime", "OffsetDateTime");
             importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
         } else if (dateLibrary.equals(DateLibrary.JAVA8_LOCALDATETIME.value)) {
+            typeMapping.put("date-time", "java.time.LocalDateTime");
             typeMapping.put("DateTime", "LocalDateTime");
             importMapping.put("LocalDateTime", "java.time.LocalDateTime");
         }
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java
index 4175924d5ae..7c77ec9ec12 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java
@@ -66,6 +66,7 @@ public class KotlinClientCodegenModelTest {
     public void simpleModelTest() {
         final Schema schema = getSimpleSchema();
         final DefaultCodegen codegen = new KotlinClientCodegen();
+        codegen.processOpts();
 
         OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
         codegen.setOpenAPI(openAPI);
diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt
index dd392773e96..dc79ef79e70 100644
--- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt
+++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt
@@ -26,7 +26,7 @@ data class Order (
     val id: kotlin.Long? = null,
     val petId: kotlin.Long? = null,
     val quantity: kotlin.Int? = null,
-    val shipDate: java.time.OffsetDateTime? = null,
+    val shipDate: java.time.LocalDateTime? = null,
     /* Order Status */
     val status: Order.Status? = null,
     val complete: kotlin.Boolean? = null
-- 
GitLab


From a91cfeec72893d069b7ad0b5ed0205fecb10e2a3 Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Fri, 20 Dec 2019 12:03:35 +0000
Subject: [PATCH 7/8] [kotlin] update pet project

---
 samples/client/petstore/kotlin-string/docs/Pet.md    |  4 ++--
 samples/client/petstore/kotlin-string/docs/PetApi.md |  8 ++++----
 .../kotlin/org/openapitools/client/apis/PetApi.kt    |  4 ++--
 .../kotlin/org/openapitools/client/models/Pet.kt     | 12 ++++++------
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/samples/client/petstore/kotlin-string/docs/Pet.md b/samples/client/petstore/kotlin-string/docs/Pet.md
index 70c340005d1..ec775600737 100644
--- a/samples/client/petstore/kotlin-string/docs/Pet.md
+++ b/samples/client/petstore/kotlin-string/docs/Pet.md
@@ -4,10 +4,10 @@
 ## Properties
 Name | Type | Description | Notes
 ------------ | ------------- | ------------- | -------------
-**name** | **kotlin.String** |  | 
-**photoUrls** | **kotlin.Array&lt;kotlin.String&gt;** |  | 
 **id** | **kotlin.Long** |  |  [optional]
 **category** | [**Category**](Category.md) |  |  [optional]
+**name** | **kotlin.String** |  | 
+**photoUrls** | **kotlin.Array&lt;kotlin.String&gt;** |  | 
 **tags** | [**kotlin.Array&lt;Tag&gt;**](Tag.md) |  |  [optional]
 **status** | [**inline**](#StatusEnum) | pet status in the store |  [optional]
 
diff --git a/samples/client/petstore/kotlin-string/docs/PetApi.md b/samples/client/petstore/kotlin-string/docs/PetApi.md
index ea93e174527..d4cc830afe0 100644
--- a/samples/client/petstore/kotlin-string/docs/PetApi.md
+++ b/samples/client/petstore/kotlin-string/docs/PetApi.md
@@ -62,7 +62,7 @@ Configure petstore_auth:
 
 <a name="deletePet"></a>
 # **deletePet**
-> deletePet(petId, apiKey)
+> deletePet(apiKey, petId)
 
 Deletes a pet
 
@@ -73,10 +73,10 @@ Deletes a pet
 //import org.openapitools.client.models.*
 
 val apiInstance = PetApi()
-val petId : kotlin.Long = 789 // kotlin.Long | Pet id to delete
 val apiKey : kotlin.String = apiKey_example // kotlin.String | 
+val petId : kotlin.Long = 789 // kotlin.Long | Pet id to delete
 try {
-    apiInstance.deletePet(petId, apiKey)
+    apiInstance.deletePet(apiKey, petId)
 } catch (e: ClientException) {
     println("4xx response calling PetApi#deletePet")
     e.printStackTrace()
@@ -90,8 +90,8 @@ try {
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **petId** | **kotlin.Long**| Pet id to delete |
  **apiKey** | **kotlin.String**|  | [optional]
+ **petId** | **kotlin.Long**| Pet id to delete |
 
 ### Return type
 
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 1638d460c68..e475ddc88d8 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
@@ -71,15 +71,15 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
     /**
     * Deletes a pet
     * 
-    * @param petId Pet id to delete 
     * @param apiKey  (optional)
+    * @param petId Pet id to delete 
     * @return void
     * @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
     */
     @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
-    fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit {
+    fun deletePet(apiKey: kotlin.String?, petId: kotlin.Long) : Unit {
         val localVariableBody: kotlin.Any? = null
         val localVariableQuery: MultiValueMap = mutableMapOf()
         val localVariableHeaders: MutableMap<String, String> = mutableMapOf("api_key" to apiKey.toString())
diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/models/Pet.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/models/Pet.kt
index eb78e6d7140..c6a47fdc0c4 100644
--- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/models/Pet.kt
+++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/models/Pet.kt
@@ -18,23 +18,23 @@ import com.squareup.moshi.Json
 import java.io.Serializable
 /**
  * A pet for sale in the pet store
- * @param name 
- * @param photoUrls 
  * @param id 
  * @param category 
+ * @param name 
+ * @param photoUrls 
  * @param tags 
  * @param status pet status in the store
  */
 
 data class Pet (
-    @Json(name = "name")
-    val name: kotlin.String,
-    @Json(name = "photoUrls")
-    val photoUrls: kotlin.Array<kotlin.String>,
     @Json(name = "id")
     val id: kotlin.Long? = null,
     @Json(name = "category")
     val category: Category? = null,
+    @Json(name = "name")
+    val name: kotlin.String,
+    @Json(name = "photoUrls")
+    val photoUrls: kotlin.Array<kotlin.String>,
     @Json(name = "tags")
     val tags: kotlin.Array<Tag>? = null,
     /* pet status in the store */
-- 
GitLab


From 70c56e47ff762aee42c5487fbd0a65094d3f03e5 Mon Sep 17 00:00:00 2001
From: Bruno Coelho <4brunu@gmail.com>
Date: Fri, 20 Dec 2019 12:16:30 +0000
Subject: [PATCH 8/8] [kotlin] update windows script

---
 bin/windows/kotlin-client-string.bat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/windows/kotlin-client-string.bat b/bin/windows/kotlin-client-string.bat
index f393eedf8f6..6e0310ecadf 100644
--- a/bin/windows/kotlin-client-string.bat
+++ b/bin/windows/kotlin-client-string.bat
@@ -5,6 +5,6 @@ If Not Exist %executable% (
 )
 
 REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
-set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin --artifact-id "kotlin-petstore-string" --additional-properties dateLibrary=string,serializableModel=true -o samples\client\petstore\kotlin-string
+set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin --artifact-id "kotlin-petstore-string" --additional-properties dateLibrary=string,serializableModel=true,sortParamsByRequiredFlag=false,sortModelPropertiesByRequiredFlag=false -o samples\client\petstore\kotlin-string
 
 java %JAVA_OPTS% -jar %executable% %ags%
-- 
GitLab