[kotlin] Add json annotation to each enum value. (#7908)

* [kotlin] Add moshi.Json annotation.

* [kotlin] update petstore samples.

* [kotlin] Remove extra new lines.
This commit is contained in:
Yukio Ejiri 2018-04-04 16:26:19 +09:00 committed by William Cheng
parent e2c58fad71
commit 3c5fb1d809
16 changed files with 50 additions and 39 deletions

View File

@ -1,3 +1,6 @@
{{#hasEnums}}
import com.squareup.moshi.Json
{{/hasEnums}}
/**
* {{{description}}}
{{#vars}}
@ -18,7 +21,7 @@ data class {{classname}} (
*/
enum class {{nameInCamelCase}}(val value: {{datatype}}){
{{#allowableValues}}{{#enumVars}}
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}{{/allowableValues}}
}
{{/isEnum}}{{/vars}}{{/hasEnums}}

View File

@ -1,9 +1,11 @@
import com.squareup.moshi.Json
/**
* {{{description}}}
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
*/
enum class {{classname}}(val value: {{dataType}}){
{{#allowableValues}}{{#enumVars}}
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}{{/allowableValues}}
}

View File

@ -213,7 +213,7 @@ Get user by user name
//import io.swagger.client.models.*
val apiInstance = UserApi()
val username : kotlin.String = username_example // kotlin.String | The name that needs to be fetched. Use user1 for testing.
val username : kotlin.String = username_example // kotlin.String | The name that needs to be fetched. Use user1 for testing.
try {
val result : User = apiInstance.getUserByName(username)
println(result)
@ -230,7 +230,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **kotlin.String**| The name that needs to be fetched. Use user1 for testing. |
**username** | **kotlin.String**| The name that needs to be fetched. Use user1 for testing. |
### Return type

View File

@ -144,7 +144,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @param username The name that needs to be fetched. Use user1 for testing.
* @return User
*/
@Suppress("UNCHECKED_CAST")

View File

@ -85,9 +85,9 @@ open class ApiClient(val baseUrl: String) {
RequestMethod.DELETE -> Request.Builder().url(url).delete()
RequestMethod.GET -> Request.Builder().url(url)
RequestMethod.HEAD -> Request.Builder().url(url).head()
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body!!, contentType))
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body!!, contentType))
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body!!, contentType))
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
}

View File

@ -12,6 +12,7 @@
package io.swagger.client.models
import com.squareup.moshi.Json
/**
* An order for a pets from the pet store
* @param id
@ -35,13 +36,13 @@ data class Order (
* Order Status
* Values: placed,approved,delivered
*/
enum class Status(val value: kotlin.Any){
enum class Status(val value: kotlin.String){
placed("placed"),
@Json(name = "placed") placed("placed"),
approved("approved"),
@Json(name = "approved") approved("approved"),
delivered("delivered");
@Json(name = "delivered") delivered("delivered");
}

View File

@ -14,6 +14,7 @@ package io.swagger.client.models
import io.swagger.client.models.Category
import io.swagger.client.models.Tag
import com.squareup.moshi.Json
/**
* A pet for sale in the pet store
* @param id
@ -37,13 +38,13 @@ data class Pet (
* pet status in the store
* Values: available,pending,sold
*/
enum class Status(val value: kotlin.Any){
enum class Status(val value: kotlin.String){
available("available"),
@Json(name = "available") available("available"),
pending("pending"),
@Json(name = "pending") pending("pending"),
sold("sold");
@Json(name = "sold") sold("sold");
}

View File

@ -213,7 +213,7 @@ Get user by user name
//import io.swagger.client.models.*
val apiInstance = UserApi()
val username : kotlin.String = username_example // kotlin.String | The name that needs to be fetched. Use user1 for testing.
val username : kotlin.String = username_example // kotlin.String | The name that needs to be fetched. Use user1 for testing.
try {
val result : User = apiInstance.getUserByName(username)
println(result)
@ -230,7 +230,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **kotlin.String**| The name that needs to be fetched. Use user1 for testing. |
**username** | **kotlin.String**| The name that needs to be fetched. Use user1 for testing. |
### Return type

View File

@ -145,7 +145,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @param username The name that needs to be fetched. Use user1 for testing.
* @return User
*/
@Suppress("UNCHECKED_CAST")

View File

@ -85,9 +85,9 @@ open class ApiClient(val baseUrl: String) {
RequestMethod.DELETE -> Request.Builder().url(url).delete()
RequestMethod.GET -> Request.Builder().url(url)
RequestMethod.HEAD -> Request.Builder().url(url).head()
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body!!, contentType))
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body!!, contentType))
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body!!, contentType))
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
}

View File

@ -13,6 +13,7 @@ package io.swagger.client.models
import org.threeten.bp.LocalDateTime
import com.squareup.moshi.Json
/**
* An order for a pets from the pet store
* @param id
@ -36,13 +37,13 @@ data class Order (
* Order Status
* Values: placed,approved,delivered
*/
enum class Status(val value: kotlin.Any){
enum class Status(val value: kotlin.String){
placed("placed"),
@Json(name = "placed") placed("placed"),
approved("approved"),
@Json(name = "approved") approved("approved"),
delivered("delivered");
@Json(name = "delivered") delivered("delivered");
}

View File

@ -15,6 +15,7 @@ import io.swagger.client.models.Category
import io.swagger.client.models.Tag
import org.threeten.bp.LocalDateTime
import com.squareup.moshi.Json
/**
* A pet for sale in the pet store
* @param id
@ -38,13 +39,13 @@ data class Pet (
* pet status in the store
* Values: available,pending,sold
*/
enum class Status(val value: kotlin.Any){
enum class Status(val value: kotlin.String){
available("available"),
@Json(name = "available") available("available"),
pending("pending"),
@Json(name = "pending") pending("pending"),
sold("sold");
@Json(name = "sold") sold("sold");
}

View File

@ -213,7 +213,7 @@ Get user by user name
//import io.swagger.client.models.*
val apiInstance = UserApi()
val username : kotlin.String = username_example // kotlin.String | The name that needs to be fetched. Use user1 for testing.
val username : kotlin.String = username_example // kotlin.String | The name that needs to be fetched. Use user1 for testing.
try {
val result : User = apiInstance.getUserByName(username)
println(result)
@ -230,7 +230,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **kotlin.String**| The name that needs to be fetched. Use user1 for testing. |
**username** | **kotlin.String**| The name that needs to be fetched. Use user1 for testing. |
### Return type

View File

@ -144,7 +144,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @param username The name that needs to be fetched. Use user1 for testing.
* @return User
*/
@Suppress("UNCHECKED_CAST")

View File

@ -12,6 +12,7 @@
package io.swagger.client.models
import com.squareup.moshi.Json
/**
* An order for a pets from the pet store
* @param id
@ -37,11 +38,11 @@ data class Order (
*/
enum class Status(val value: kotlin.String){
placed("placed"),
@Json(name = "placed") placed("placed"),
approved("approved"),
@Json(name = "approved") approved("approved"),
delivered("delivered");
@Json(name = "delivered") delivered("delivered");
}

View File

@ -14,6 +14,7 @@ package io.swagger.client.models
import io.swagger.client.models.Category
import io.swagger.client.models.Tag
import com.squareup.moshi.Json
/**
* A pet for sale in the pet store
* @param id
@ -39,11 +40,11 @@ data class Pet (
*/
enum class Status(val value: kotlin.String){
available("available"),
@Json(name = "available") available("available"),
pending("pending"),
@Json(name = "pending") pending("pending"),
sold("sold");
@Json(name = "sold") sold("sold");
}