mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-05 15:10:49 +00:00
[kotlin] Support nested enums in models (#5769)
* [kotlin] Add model enum support Model variables marked isEnum=true are nested class enums. Top-level enums will not be isEnum=true, but rather have a datatype specific to the enum's type. * [kotlin] Regenerate client sample
This commit is contained in:
parent
879149bb69
commit
ef07a02a01
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* {{{description}}}
|
||||
{{#vars}}
|
||||
* @param {{name}} {{{description}}}
|
||||
{{/vars}}
|
||||
*/
|
||||
data class {{classname}} (
|
||||
{{#requiredVars}}
|
||||
{{>data_class_req_var}}{{^-last}},
|
||||
{{/-last}}{{/requiredVars}}{{#hasRequired}},
|
||||
{{/hasRequired}}{{#optionalVars}}{{>data_class_opt_var}}{{^-last}},
|
||||
{{/-last}}{{/optionalVars}}
|
||||
) {
|
||||
{{#hasEnums}}{{#vars}}{{#isEnum}}
|
||||
enum class {{nameInCamelCase}}(val value: {{datatype}}) {
|
||||
{{#_enum}}
|
||||
{{{this}}}({{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/_enum}}
|
||||
}
|
||||
|
||||
{{/isEnum}}{{/vars}}{{/hasEnums}}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{{#description}}
|
||||
/* {{{description}}} */
|
||||
{{/description}}
|
||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
@ -0,0 +1,4 @@
|
||||
{{#description}}
|
||||
/* {{{description}}} */
|
||||
{{/description}}
|
||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}
|
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* {{{description}}}
|
||||
* Values: {{#allowableValues}}{{#enumVars}}{{name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
*/
|
||||
enum class {{classname}}(val value: {{dataType}}){
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
{{name}}({{#isString}}"{{/isString}}{{{value}}}{{#isString}}"{{/isString}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
)
|
@ -6,19 +6,6 @@ package {{modelPackage}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
{{#vars}}
|
||||
* @param {{name}} {{{description}}}
|
||||
{{/vars}}
|
||||
*/
|
||||
data class {{classname}} (
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/* {{{description}}} */
|
||||
{{/description}}
|
||||
val {{{name}}}: {{{datatype}}}{{^required}}?{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/vars}}
|
||||
)
|
||||
{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{>data_class}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
@ -19,7 +19,9 @@ package io.swagger.client.models
|
||||
* @param message
|
||||
*/
|
||||
data class ApiResponse (
|
||||
val code: kotlin.Int?,
|
||||
val type: kotlin.String?,
|
||||
val message: kotlin.String?
|
||||
)
|
||||
val code: kotlin.Int? = null,
|
||||
val type: kotlin.String? = null,
|
||||
val message: kotlin.String? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ package io.swagger.client.models
|
||||
* @param name
|
||||
*/
|
||||
data class Category (
|
||||
val id: kotlin.Long?,
|
||||
val name: kotlin.String?
|
||||
)
|
||||
val id: kotlin.Long? = null,
|
||||
val name: kotlin.String? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
@ -22,11 +22,20 @@ package io.swagger.client.models
|
||||
* @param complete
|
||||
*/
|
||||
data class Order (
|
||||
val id: kotlin.Long?,
|
||||
val petId: kotlin.Long?,
|
||||
val quantity: kotlin.Int?,
|
||||
val shipDate: java.time.LocalDateTime?,
|
||||
val id: kotlin.Long? = null,
|
||||
val petId: kotlin.Long? = null,
|
||||
val quantity: kotlin.Int? = null,
|
||||
val shipDate: java.time.LocalDateTime? = null,
|
||||
/* Order Status */
|
||||
val status: kotlin.String?,
|
||||
val complete: kotlin.Boolean?
|
||||
)
|
||||
val status: Order.Status? = null,
|
||||
val complete: kotlin.Boolean? = null
|
||||
) {
|
||||
|
||||
enum class Status(val value: kotlin.String) {
|
||||
placed("placed"),
|
||||
approved("approved"),
|
||||
delivered("delivered");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,11 +24,20 @@ import io.swagger.client.models.Tag
|
||||
* @param status pet status in the store
|
||||
*/
|
||||
data class Pet (
|
||||
val id: kotlin.Long?,
|
||||
val category: Category?,
|
||||
val name: kotlin.String,
|
||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||
val tags: kotlin.collections.List<Tag>?,
|
||||
val id: kotlin.Long? = null,
|
||||
val category: Category? = null,
|
||||
val tags: kotlin.collections.List<Tag>? = null,
|
||||
/* pet status in the store */
|
||||
val status: kotlin.String?
|
||||
)
|
||||
val status: Pet.Status? = null
|
||||
) {
|
||||
|
||||
enum class Status(val value: kotlin.String) {
|
||||
available("available"),
|
||||
pending("pending"),
|
||||
sold("sold");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ package io.swagger.client.models
|
||||
* @param name
|
||||
*/
|
||||
data class Tag (
|
||||
val id: kotlin.Long?,
|
||||
val name: kotlin.String?
|
||||
)
|
||||
val id: kotlin.Long? = null,
|
||||
val name: kotlin.String? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
@ -24,13 +24,15 @@ package io.swagger.client.models
|
||||
* @param userStatus User Status
|
||||
*/
|
||||
data class User (
|
||||
val id: kotlin.Long?,
|
||||
val username: kotlin.String?,
|
||||
val firstName: kotlin.String?,
|
||||
val lastName: kotlin.String?,
|
||||
val email: kotlin.String?,
|
||||
val password: kotlin.String?,
|
||||
val phone: kotlin.String?,
|
||||
val id: kotlin.Long? = null,
|
||||
val username: kotlin.String? = null,
|
||||
val firstName: kotlin.String? = null,
|
||||
val lastName: kotlin.String? = null,
|
||||
val email: kotlin.String? = null,
|
||||
val password: kotlin.String? = null,
|
||||
val phone: kotlin.String? = null,
|
||||
/* User Status */
|
||||
val userStatus: kotlin.Int?
|
||||
)
|
||||
val userStatus: kotlin.Int? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class EvaluateTest : ShouldSpec() {
|
||||
init {
|
||||
should("query against pet statuses") {
|
||||
val api = PetApi()
|
||||
val results = api.findPetsByStatus(listOf("available", "pending"))
|
||||
val results = api.findPetsByStatus(listOf("sold"))
|
||||
|
||||
results.size should beGreaterThan(1)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user