mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 00:43:46 +00:00
[kotlin][client] Add Jackson to interface properties and remove extra line feed (#5459)
* [kotlin][client] Ensure Jackson annotations are consistent with interface vars * [kotlin][client] Rebuild samples * [kotlin][client] Some kotlin client enhancements - Don't use JsonFormat for Date objects, this should be controlled via a custom serializer/deserializer or a turning on and off serialization features of Jackson. I've updated the jacksonObjectMapper config to write the dates as strings, which I think was intended in the original commit. https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/SerializationFeature.html#WRITE_DATES_AS_TIMESTAMPS https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/cfg/MapperConfig.html#getDateFormat-- - Dont' use @JsonFormat(shape = JsonFormat.Shape.OBJECT) for enums. This causes Enums to be formatted as objects with an internal "value" field. In reality, OpenAPI enums are just strings without properties and should be treated as a string. https://www.baeldung.com/jackson-serialize-enums#2-enum-as-json-object - Add's Kotlin use site annotation @get: to JsonProperty for parent interface properties. Otherwise Kotlin will warn: "This annotation is not applicable to target 'member property without backing field or delegate'" - Add's JsonTypeInfo annotations to interfaces for inheritance. This was copied verbatim from the kotlin-spring generator. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-spring/typeInfoAnnotation.mustache * [kotlin][client] Rebuild kotlin samples
This commit is contained in:
@@ -22,13 +22,10 @@ import com.squareup.moshi.Json
|
||||
|
||||
data class ApiResponse (
|
||||
@Json(name = "code")
|
||||
val code: kotlin.Int? = null
|
||||
,
|
||||
val code: kotlin.Int? = null,
|
||||
@Json(name = "type")
|
||||
val type: kotlin.String? = null
|
||||
,
|
||||
val type: kotlin.String? = null,
|
||||
@Json(name = "message")
|
||||
val message: kotlin.String? = null
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -21,10 +21,8 @@ import com.squareup.moshi.Json
|
||||
|
||||
data class Category (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null
|
||||
,
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String? = null
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -25,24 +25,18 @@ import com.squareup.moshi.Json
|
||||
|
||||
data class Order (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null
|
||||
,
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "petId")
|
||||
val petId: kotlin.Long? = null
|
||||
,
|
||||
val petId: kotlin.Long? = null,
|
||||
@Json(name = "quantity")
|
||||
val quantity: kotlin.Int? = null
|
||||
,
|
||||
val quantity: kotlin.Int? = null,
|
||||
@Json(name = "shipDate")
|
||||
val shipDate: java.time.OffsetDateTime? = null
|
||||
,
|
||||
val shipDate: java.time.OffsetDateTime? = null,
|
||||
/* Order Status */
|
||||
@Json(name = "status")
|
||||
val status: Order.Status? = null
|
||||
,
|
||||
val status: Order.Status? = null,
|
||||
@Json(name = "complete")
|
||||
val complete: kotlin.Boolean? = null
|
||||
|
||||
) {
|
||||
|
||||
/**
|
||||
@@ -50,7 +44,6 @@ data class Order (
|
||||
* Values: placed,approved,delivered
|
||||
*/
|
||||
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@Json(name = "placed") placed("placed"),
|
||||
@Json(name = "approved") approved("approved"),
|
||||
|
||||
@@ -27,24 +27,18 @@ import com.squareup.moshi.Json
|
||||
|
||||
data class Pet (
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String
|
||||
,
|
||||
val name: kotlin.String,
|
||||
@Json(name = "photoUrls")
|
||||
val photoUrls: kotlin.Array<kotlin.String>
|
||||
,
|
||||
val photoUrls: kotlin.Array<kotlin.String>,
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null
|
||||
,
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "category")
|
||||
val category: Category? = null
|
||||
,
|
||||
val category: Category? = null,
|
||||
@Json(name = "tags")
|
||||
val tags: kotlin.Array<Tag>? = null
|
||||
,
|
||||
val tags: kotlin.Array<Tag>? = null,
|
||||
/* pet status in the store */
|
||||
@Json(name = "status")
|
||||
val status: Pet.Status? = null
|
||||
|
||||
) {
|
||||
|
||||
/**
|
||||
@@ -52,7 +46,6 @@ data class Pet (
|
||||
* Values: available,pending,sold
|
||||
*/
|
||||
|
||||
|
||||
enum class Status(val value: kotlin.String){
|
||||
@Json(name = "available") available("available"),
|
||||
@Json(name = "pending") pending("pending"),
|
||||
|
||||
@@ -21,10 +21,8 @@ import com.squareup.moshi.Json
|
||||
|
||||
data class Tag (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null
|
||||
,
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "name")
|
||||
val name: kotlin.String? = null
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -27,29 +27,21 @@ import com.squareup.moshi.Json
|
||||
|
||||
data class User (
|
||||
@Json(name = "id")
|
||||
val id: kotlin.Long? = null
|
||||
,
|
||||
val id: kotlin.Long? = null,
|
||||
@Json(name = "username")
|
||||
val username: kotlin.String? = null
|
||||
,
|
||||
val username: kotlin.String? = null,
|
||||
@Json(name = "firstName")
|
||||
val firstName: kotlin.String? = null
|
||||
,
|
||||
val firstName: kotlin.String? = null,
|
||||
@Json(name = "lastName")
|
||||
val lastName: kotlin.String? = null
|
||||
,
|
||||
val lastName: kotlin.String? = null,
|
||||
@Json(name = "email")
|
||||
val email: kotlin.String? = null
|
||||
,
|
||||
val email: kotlin.String? = null,
|
||||
@Json(name = "password")
|
||||
val password: kotlin.String? = null
|
||||
,
|
||||
val password: kotlin.String? = null,
|
||||
@Json(name = "phone")
|
||||
val phone: kotlin.String? = null
|
||||
,
|
||||
val phone: kotlin.String? = null,
|
||||
/* User Status */
|
||||
@Json(name = "userStatus")
|
||||
val userStatus: kotlin.Int? = null
|
||||
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user