Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kotlin-spring] Allow DateTime to be remapped to others (LocalDateTIme) #1740

Conversation

jimschubert
Copy link
Member

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Allows kotlin-spring to override the DateTime mappings in order to use LocalDateTime (#1731)

Examples:

kotlin-spring

openapi-generator generate \
    -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
    -t modules/openapi-generator/src/main/resources/kotlin-spring \
    -g kotlin-spring \
    -o samples/server/petstore/kotlin-springboot \
    --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true \
    --import-mappings=DateTime=java.time.LocalDateTime \
    --type-mappings=DateTime=java.time.LocalDateTime

This regenerates the kotlin-spring example with LocalDateTime:

diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt
index e1065f56bd..ad989c3b46 100644
--- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt
+++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt
@@ -18,22 +18,22 @@ import io.swagger.annotations.ApiModelProperty
  */
 data class Order (

-        @ApiModelProperty(value = "")
+        @ApiModelProperty(example = "null", value = "")
         @JsonProperty("id") val id: Long? = null,

-        @ApiModelProperty(value = "")
+        @ApiModelProperty(example = "null", value = "")
         @JsonProperty("petId") val petId: Long? = null,

-        @ApiModelProperty(value = "")
+        @ApiModelProperty(example = "null", value = "")
         @JsonProperty("quantity") val quantity: Int? = null,

-        @ApiModelProperty(value = "")
-        @JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null,
+        @ApiModelProperty(example = "null", value = "")
+        @JsonProperty("shipDate") val shipDate: java.time.LocalDateTime? = null,

-        @ApiModelProperty(value = "Order Status")
+        @ApiModelProperty(example = "null", value = "Order Status")
         @JsonProperty("status") val status: Order.Status? = null,

-        @ApiModelProperty(value = "")
+        @ApiModelProperty(example = "null", value = "")
         @JsonProperty("complete") val complete: Boolean? = null
 ) {

kotlin (client)

The client itself defaults to LocalDateTime, so here's how to change it to OffsetDateTime:

openapi-generator generate \
    -t modules/openapi-generator/src/main/resources/kotlin-client \
    -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
    -g kotlin --artifact-id kotlin-petstore-client \
    -D dateLibrary=java8 -o samples/client/petstore/kotlin \
    --import-mappings=DateTime=java.time.OffsetDateTime \
    --type-mappings=DateTime=java.time.OffsetDateTime

outputs:

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 44a8b1f896..0a163169be 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
@@ -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

/cc @ackintosh

@auto-labeler
Copy link

auto-labeler bot commented Dec 22, 2018

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

Copy link
Contributor

@ackintosh ackintosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I've checked that works as expected. 👍

@wing328 wing328 added this to the 4.0.0 milestone Dec 23, 2018
@wing328 wing328 merged commit 92badd8 into OpenAPITools:master Dec 23, 2018
@jimschubert jimschubert deleted the fix-kotlin-spring-import-type-mappings branch January 5, 2019 01:33
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants