mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
[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:
parent
e2c58fad71
commit
3c5fb1d809
@ -1,3 +1,6 @@
|
|||||||
|
{{#hasEnums}}
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
{{/hasEnums}}
|
||||||
/**
|
/**
|
||||||
* {{{description}}}
|
* {{{description}}}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
@ -18,7 +21,7 @@ data class {{classname}} (
|
|||||||
*/
|
*/
|
||||||
enum class {{nameInCamelCase}}(val value: {{datatype}}){
|
enum class {{nameInCamelCase}}(val value: {{datatype}}){
|
||||||
{{#allowableValues}}{{#enumVars}}
|
{{#allowableValues}}{{#enumVars}}
|
||||||
{{&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}}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
import com.squareup.moshi.Json
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {{{description}}}
|
* {{{description}}}
|
||||||
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||||
*/
|
*/
|
||||||
enum class {{classname}}(val value: {{dataType}}){
|
enum class {{classname}}(val value: {{dataType}}){
|
||||||
{{#allowableValues}}{{#enumVars}}
|
{{#allowableValues}}{{#enumVars}}
|
||||||
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||||
{{/enumVars}}{{/allowableValues}}
|
{{/enumVars}}{{/allowableValues}}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ Get user by user name
|
|||||||
//import io.swagger.client.models.*
|
//import io.swagger.client.models.*
|
||||||
|
|
||||||
val apiInstance = UserApi()
|
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 {
|
try {
|
||||||
val result : User = apiInstance.getUserByName(username)
|
val result : User = apiInstance.getUserByName(username)
|
||||||
println(result)
|
println(result)
|
||||||
@ -230,7 +230,7 @@ try {
|
|||||||
|
|
||||||
Name | Type | Description | Notes
|
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
|
### Return type
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
|
|||||||
/**
|
/**
|
||||||
* Get user by user name
|
* 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
|
* @return User
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
@ -85,9 +85,9 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete()
|
RequestMethod.DELETE -> Request.Builder().url(url).delete()
|
||||||
RequestMethod.GET -> Request.Builder().url(url)
|
RequestMethod.GET -> Request.Builder().url(url)
|
||||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body!!, contentType))
|
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body!!, contentType))
|
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body!!, contentType))
|
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
package io.swagger.client.models
|
package io.swagger.client.models
|
||||||
|
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
/**
|
/**
|
||||||
* An order for a pets from the pet store
|
* An order for a pets from the pet store
|
||||||
* @param id
|
* @param id
|
||||||
@ -35,13 +36,13 @@ data class Order (
|
|||||||
* Order Status
|
* Order Status
|
||||||
* Values: placed,approved,delivered
|
* 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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ package io.swagger.client.models
|
|||||||
import io.swagger.client.models.Category
|
import io.swagger.client.models.Category
|
||||||
import io.swagger.client.models.Tag
|
import io.swagger.client.models.Tag
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
/**
|
/**
|
||||||
* A pet for sale in the pet store
|
* A pet for sale in the pet store
|
||||||
* @param id
|
* @param id
|
||||||
@ -37,13 +38,13 @@ data class Pet (
|
|||||||
* pet status in the store
|
* pet status in the store
|
||||||
* Values: available,pending,sold
|
* 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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ Get user by user name
|
|||||||
//import io.swagger.client.models.*
|
//import io.swagger.client.models.*
|
||||||
|
|
||||||
val apiInstance = UserApi()
|
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 {
|
try {
|
||||||
val result : User = apiInstance.getUserByName(username)
|
val result : User = apiInstance.getUserByName(username)
|
||||||
println(result)
|
println(result)
|
||||||
@ -230,7 +230,7 @@ try {
|
|||||||
|
|
||||||
Name | Type | Description | Notes
|
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
|
### Return type
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
|
|||||||
/**
|
/**
|
||||||
* Get user by user name
|
* 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
|
* @return User
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
@ -85,9 +85,9 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete()
|
RequestMethod.DELETE -> Request.Builder().url(url).delete()
|
||||||
RequestMethod.GET -> Request.Builder().url(url)
|
RequestMethod.GET -> Request.Builder().url(url)
|
||||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body!!, contentType))
|
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||||
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body!!, contentType))
|
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(body, contentType))
|
||||||
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body!!, contentType))
|
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(body, contentType))
|
||||||
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ package io.swagger.client.models
|
|||||||
|
|
||||||
import org.threeten.bp.LocalDateTime
|
import org.threeten.bp.LocalDateTime
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
/**
|
/**
|
||||||
* An order for a pets from the pet store
|
* An order for a pets from the pet store
|
||||||
* @param id
|
* @param id
|
||||||
@ -36,13 +37,13 @@ data class Order (
|
|||||||
* Order Status
|
* Order Status
|
||||||
* Values: placed,approved,delivered
|
* 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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import io.swagger.client.models.Category
|
|||||||
import io.swagger.client.models.Tag
|
import io.swagger.client.models.Tag
|
||||||
import org.threeten.bp.LocalDateTime
|
import org.threeten.bp.LocalDateTime
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
/**
|
/**
|
||||||
* A pet for sale in the pet store
|
* A pet for sale in the pet store
|
||||||
* @param id
|
* @param id
|
||||||
@ -38,13 +39,13 @@ data class Pet (
|
|||||||
* pet status in the store
|
* pet status in the store
|
||||||
* Values: available,pending,sold
|
* 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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ Get user by user name
|
|||||||
//import io.swagger.client.models.*
|
//import io.swagger.client.models.*
|
||||||
|
|
||||||
val apiInstance = UserApi()
|
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 {
|
try {
|
||||||
val result : User = apiInstance.getUserByName(username)
|
val result : User = apiInstance.getUserByName(username)
|
||||||
println(result)
|
println(result)
|
||||||
@ -230,7 +230,7 @@ try {
|
|||||||
|
|
||||||
Name | Type | Description | Notes
|
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
|
### Return type
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
|
|||||||
/**
|
/**
|
||||||
* Get user by user name
|
* 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
|
* @return User
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
package io.swagger.client.models
|
package io.swagger.client.models
|
||||||
|
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
/**
|
/**
|
||||||
* An order for a pets from the pet store
|
* An order for a pets from the pet store
|
||||||
* @param id
|
* @param id
|
||||||
@ -37,11 +38,11 @@ data class Order (
|
|||||||
*/
|
*/
|
||||||
enum class Status(val value: kotlin.String){
|
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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ package io.swagger.client.models
|
|||||||
import io.swagger.client.models.Category
|
import io.swagger.client.models.Category
|
||||||
import io.swagger.client.models.Tag
|
import io.swagger.client.models.Tag
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
/**
|
/**
|
||||||
* A pet for sale in the pet store
|
* A pet for sale in the pet store
|
||||||
* @param id
|
* @param id
|
||||||
@ -39,11 +40,11 @@ data class Pet (
|
|||||||
*/
|
*/
|
||||||
enum class Status(val value: kotlin.String){
|
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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user