Skip to content

Commit

Permalink
[kotlin] Add json annotation to each enum value. (#7908)
Browse files Browse the repository at this point in the history
* [kotlin] Add moshi.Json annotation.

* [kotlin] update petstore samples.

* [kotlin] Remove extra new lines.
  • Loading branch information
ejithon authored and wing328 committed Apr 4, 2018
1 parent e2c58fa commit 3c5fb1d
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{#hasEnums}}
import com.squareup.moshi.Json
{{/hasEnums}}
/**
* {{{description}}}
{{#vars}}
Expand All @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}
}
4 changes: 2 additions & 2 deletions samples/client/petstore/kotlin-string/docs/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

}

Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/kotlin-threetenbp/docs/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

}

Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/kotlin/docs/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

}

Expand Down

0 comments on commit 3c5fb1d

Please sign in to comment.