diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/data_class.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/data_class.mustache index e64785e01b1..66cc4ac838e 100644 --- a/modules/swagger-codegen/src/main/resources/kotlin-client/data_class.mustache +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/data_class.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/kotlin-client/enum_class.mustache b/modules/swagger-codegen/src/main/resources/kotlin-client/enum_class.mustache index 791398b9789..6b85b0fba53 100644 --- a/modules/swagger-codegen/src/main/resources/kotlin-client/enum_class.mustache +++ b/modules/swagger-codegen/src/main/resources/kotlin-client/enum_class.mustache @@ -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}} } diff --git a/samples/client/petstore/kotlin-string/docs/UserApi.md b/samples/client/petstore/kotlin-string/docs/UserApi.md index d15aae23da3..0c4b9b79de8 100644 --- a/samples/client/petstore/kotlin-string/docs/UserApi.md +++ b/samples/client/petstore/kotlin-string/docs/UserApi.md @@ -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 diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/UserApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/UserApi.kt index d3d80fe76ab..9bd50f0f4c0 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/apis/UserApi.kt @@ -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") diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt index da178750688..eb13afafce6 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt @@ -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) } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Order.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Order.kt index 043ffe9baf1..98b2a75b05d 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Order.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Order.kt @@ -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"); } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Pet.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Pet.kt index c507522da92..4008a46203c 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Pet.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/models/Pet.kt @@ -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"); } diff --git a/samples/client/petstore/kotlin-threetenbp/docs/UserApi.md b/samples/client/petstore/kotlin-threetenbp/docs/UserApi.md index d15aae23da3..0c4b9b79de8 100644 --- a/samples/client/petstore/kotlin-threetenbp/docs/UserApi.md +++ b/samples/client/petstore/kotlin-threetenbp/docs/UserApi.md @@ -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 diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/UserApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/UserApi.kt index 3d2dabddad7..a7c647ce1e1 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/apis/UserApi.kt @@ -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") diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt index da178750688..eb13afafce6 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt @@ -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) } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Order.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Order.kt index e8a67e55bf9..ced79e3553c 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Order.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Order.kt @@ -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"); } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Pet.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Pet.kt index 5ba0d7c6309..df45756efac 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Pet.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/models/Pet.kt @@ -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"); } diff --git a/samples/client/petstore/kotlin/docs/UserApi.md b/samples/client/petstore/kotlin/docs/UserApi.md index d15aae23da3..0c4b9b79de8 100644 --- a/samples/client/petstore/kotlin/docs/UserApi.md +++ b/samples/client/petstore/kotlin/docs/UserApi.md @@ -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 diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt index d3d80fe76ab..9bd50f0f4c0 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt @@ -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") diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt index 78afb772e9a..718a31cd0d3 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt @@ -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"); } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt index 8c0256b3be8..4008a46203c 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt @@ -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"); }