[BUG][Kotlin Client] API using case other than camelCase not generated properly (#2391)

* Add Json import for all data classes

* Add `@Json` annotation for data class required variables

* Add `@json` annotation for data class optional variables

* Update samples code (petstore, strings, threetenbp)

* Fix annotation to match Kotlin coding style
This commit is contained in:
Mathieu Lemoine 2019-03-26 21:59:39 -04:00 committed by William Cheng
parent 6e7c621629
commit 81c57eefd5
22 changed files with 135 additions and 22 deletions

View File

@ -1,6 +1,4 @@
{{#hasEnums}}
import com.squareup.moshi.Json import com.squareup.moshi.Json
{{/hasEnums}}
{{#parcelizeModels}} {{#parcelizeModels}}
import android.os.Parcelable import android.os.Parcelable
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@ -29,7 +27,8 @@ data class {{classname}} (
*/ */
enum class {{nameInCamelCase}}(val value: {{dataType}}){ enum class {{nameInCamelCase}}(val value: {{dataType}}){
{{#allowableValues}}{{#enumVars}} {{#allowableValues}}{{#enumVars}}
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} @Json(name = {{{value}}})
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}{{/allowableValues}} {{/enumVars}}{{/allowableValues}}
} }
{{/isEnum}}{{/vars}}{{/hasEnums}} {{/isEnum}}{{/vars}}{{/hasEnums}}

View File

@ -1,4 +1,5 @@
{{#description}} {{#description}}
/* {{{description}}} */ /* {{{description}}} */
{{/description}} {{/description}}
@Json(name = "{{{baseName}}}")
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}} val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}

View File

@ -1,4 +1,5 @@
{{#description}} {{#description}}
/* {{{description}}} */ /* {{{description}}} */
{{/description}} {{/description}}
@Json(name = "{{{baseName}}}")
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}

View File

@ -6,6 +6,7 @@ import com.squareup.moshi.Json
*/ */
enum class {{classname}}(val value: {{dataType}}){ enum class {{classname}}(val value: {{dataType}}){
{{#allowableValues}}{{#enumVars}} {{#allowableValues}}{{#enumVars}}
@Json(name = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} @Json(name = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}})
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}{{/allowableValues}} {{/enumVars}}{{/allowableValues}}
} }

View File

@ -12,6 +12,7 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* Describes the result of uploading an image resource * Describes the result of uploading an image resource
* @param code * @param code
@ -19,8 +20,11 @@ package org.openapitools.client.models
* @param message * @param message
*/ */
data class ApiResponse ( 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 val message: kotlin.String? = null
) { ) {

View File

@ -12,13 +12,16 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* A category for a pet * A category for a pet
* @param id * @param id
* @param name * @param name
*/ */
data class Category ( data class Category (
@Json(name = "id")
val id: kotlin.Long? = null, val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null val name: kotlin.String? = null
) { ) {

View File

@ -23,12 +23,18 @@ import com.squareup.moshi.Json
* @param complete * @param complete
*/ */
data class Order ( 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: kotlin.String? = null, val shipDate: kotlin.String? = null,
/* Order Status */ /* Order Status */
@Json(name = "status")
val status: Order.Status? = null, val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null val complete: kotlin.Boolean? = null
) { ) {
@ -38,11 +44,14 @@ data class Order (
*/ */
enum class Status(val value: kotlin.String){ enum class Status(val value: kotlin.String){
@Json(name = "placed") placed("placed"), @Json(name = "placed")
placed("placed"),
@Json(name = "approved") approved("approved"), @Json(name = "approved")
approved("approved"),
@Json(name = "delivered") delivered("delivered"); @Json(name = "delivered")
delivered("delivered");
} }

View File

@ -25,12 +25,18 @@ import com.squareup.moshi.Json
* @param status pet status in the store * @param status pet status in the store
*/ */
data class Pet ( 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 */ /* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null val status: Pet.Status? = null
) { ) {
@ -40,11 +46,14 @@ data class Pet (
*/ */
enum class Status(val value: kotlin.String){ enum class Status(val value: kotlin.String){
@Json(name = "available") available("available"), @Json(name = "available")
available("available"),
@Json(name = "pending") pending("pending"), @Json(name = "pending")
pending("pending"),
@Json(name = "sold") sold("sold"); @Json(name = "sold")
sold("sold");
} }

View File

@ -12,13 +12,16 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* A tag for a pet * A tag for a pet
* @param id * @param id
* @param name * @param name
*/ */
data class Tag ( data class Tag (
@Json(name = "id")
val id: kotlin.Long? = null, val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null val name: kotlin.String? = null
) { ) {

View File

@ -12,6 +12,7 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* A User who is purchasing from the pet store * A User who is purchasing from the pet store
* @param id * @param id
@ -24,14 +25,22 @@ package org.openapitools.client.models
* @param userStatus User Status * @param userStatus User Status
*/ */
data class User ( 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 */ /* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null val userStatus: kotlin.Int? = null
) { ) {

View File

@ -13,6 +13,7 @@ package org.openapitools.client.models
import org.threeten.bp.LocalDateTime import org.threeten.bp.LocalDateTime
import com.squareup.moshi.Json
/** /**
* Describes the result of uploading an image resource * Describes the result of uploading an image resource
* @param code * @param code
@ -20,8 +21,11 @@ import org.threeten.bp.LocalDateTime
* @param message * @param message
*/ */
data class ApiResponse ( 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 val message: kotlin.String? = null
) { ) {

View File

@ -13,13 +13,16 @@ package org.openapitools.client.models
import org.threeten.bp.LocalDateTime import org.threeten.bp.LocalDateTime
import com.squareup.moshi.Json
/** /**
* A category for a pet * A category for a pet
* @param id * @param id
* @param name * @param name
*/ */
data class Category ( data class Category (
@Json(name = "id")
val id: kotlin.Long? = null, val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null val name: kotlin.String? = null
) { ) {

View File

@ -24,12 +24,18 @@ import com.squareup.moshi.Json
* @param complete * @param complete
*/ */
data class Order ( 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: org.threeten.bp.LocalDateTime? = null, val shipDate: org.threeten.bp.LocalDateTime? = null,
/* Order Status */ /* Order Status */
@Json(name = "status")
val status: Order.Status? = null, val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null val complete: kotlin.Boolean? = null
) { ) {
@ -39,11 +45,14 @@ data class Order (
*/ */
enum class Status(val value: kotlin.String){ enum class Status(val value: kotlin.String){
@Json(name = "placed") placed("placed"), @Json(name = "placed")
placed("placed"),
@Json(name = "approved") approved("approved"), @Json(name = "approved")
approved("approved"),
@Json(name = "delivered") delivered("delivered"); @Json(name = "delivered")
delivered("delivered");
} }

View File

@ -26,12 +26,18 @@ import com.squareup.moshi.Json
* @param status pet status in the store * @param status pet status in the store
*/ */
data class Pet ( 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 */ /* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null val status: Pet.Status? = null
) { ) {
@ -41,11 +47,14 @@ data class Pet (
*/ */
enum class Status(val value: kotlin.String){ enum class Status(val value: kotlin.String){
@Json(name = "available") available("available"), @Json(name = "available")
available("available"),
@Json(name = "pending") pending("pending"), @Json(name = "pending")
pending("pending"),
@Json(name = "sold") sold("sold"); @Json(name = "sold")
sold("sold");
} }

View File

@ -13,13 +13,16 @@ package org.openapitools.client.models
import org.threeten.bp.LocalDateTime import org.threeten.bp.LocalDateTime
import com.squareup.moshi.Json
/** /**
* A tag for a pet * A tag for a pet
* @param id * @param id
* @param name * @param name
*/ */
data class Tag ( data class Tag (
@Json(name = "id")
val id: kotlin.Long? = null, val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null val name: kotlin.String? = null
) { ) {

View File

@ -13,6 +13,7 @@ package org.openapitools.client.models
import org.threeten.bp.LocalDateTime import org.threeten.bp.LocalDateTime
import com.squareup.moshi.Json
/** /**
* A User who is purchasing from the pet store * A User who is purchasing from the pet store
* @param id * @param id
@ -25,14 +26,22 @@ import org.threeten.bp.LocalDateTime
* @param userStatus User Status * @param userStatus User Status
*/ */
data class User ( 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 */ /* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null val userStatus: kotlin.Int? = null
) { ) {

View File

@ -12,6 +12,7 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* Describes the result of uploading an image resource * Describes the result of uploading an image resource
* @param code * @param code
@ -19,8 +20,11 @@ package org.openapitools.client.models
* @param message * @param message
*/ */
data class ApiResponse ( 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 val message: kotlin.String? = null
) { ) {

View File

@ -12,13 +12,16 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* A category for a pet * A category for a pet
* @param id * @param id
* @param name * @param name
*/ */
data class Category ( data class Category (
@Json(name = "id")
val id: kotlin.Long? = null, val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null val name: kotlin.String? = null
) { ) {

View File

@ -23,12 +23,18 @@ import com.squareup.moshi.Json
* @param complete * @param complete
*/ */
data class Order ( 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.LocalDateTime? = null, val shipDate: java.time.LocalDateTime? = null,
/* Order Status */ /* Order Status */
@Json(name = "status")
val status: Order.Status? = null, val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null val complete: kotlin.Boolean? = null
) { ) {
@ -38,11 +44,14 @@ data class Order (
*/ */
enum class Status(val value: kotlin.String){ enum class Status(val value: kotlin.String){
@Json(name = "placed") placed("placed"), @Json(name = "placed")
placed("placed"),
@Json(name = "approved") approved("approved"), @Json(name = "approved")
approved("approved"),
@Json(name = "delivered") delivered("delivered"); @Json(name = "delivered")
delivered("delivered");
} }

View File

@ -25,12 +25,18 @@ import com.squareup.moshi.Json
* @param status pet status in the store * @param status pet status in the store
*/ */
data class Pet ( 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 */ /* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null val status: Pet.Status? = null
) { ) {
@ -40,11 +46,14 @@ data class Pet (
*/ */
enum class Status(val value: kotlin.String){ enum class Status(val value: kotlin.String){
@Json(name = "available") available("available"), @Json(name = "available")
available("available"),
@Json(name = "pending") pending("pending"), @Json(name = "pending")
pending("pending"),
@Json(name = "sold") sold("sold"); @Json(name = "sold")
sold("sold");
} }

View File

@ -12,13 +12,16 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* A tag for a pet * A tag for a pet
* @param id * @param id
* @param name * @param name
*/ */
data class Tag ( data class Tag (
@Json(name = "id")
val id: kotlin.Long? = null, val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null val name: kotlin.String? = null
) { ) {

View File

@ -12,6 +12,7 @@
package org.openapitools.client.models package org.openapitools.client.models
import com.squareup.moshi.Json
/** /**
* A User who is purchasing from the pet store * A User who is purchasing from the pet store
* @param id * @param id
@ -24,14 +25,22 @@ package org.openapitools.client.models
* @param userStatus User Status * @param userStatus User Status
*/ */
data class User ( 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 */ /* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null val userStatus: kotlin.Int? = null
) { ) {