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}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
/**
|
{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{>data_class}}{{/isEnum}}
|
||||||
* {{{description}}}
|
|
||||||
{{#vars}}
|
|
||||||
* @param {{name}} {{{description}}}
|
|
||||||
{{/vars}}
|
|
||||||
*/
|
|
||||||
data class {{classname}} (
|
|
||||||
{{#vars}}
|
|
||||||
{{#description}}
|
|
||||||
/* {{{description}}} */
|
|
||||||
{{/description}}
|
|
||||||
val {{{name}}}: {{{datatype}}}{{^required}}?{{/required}}{{#hasMore}},{{/hasMore}}
|
|
||||||
{{/vars}}
|
|
||||||
)
|
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
||||||
|
@ -13,13 +13,15 @@ package io.swagger.client.models
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the result of uploading an image resource
|
* Describes the result of uploading an image resource
|
||||||
* @param code
|
* @param code
|
||||||
* @param type
|
* @param type
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
data class ApiResponse (
|
data class ApiResponse (
|
||||||
val code: kotlin.Int?,
|
val code: kotlin.Int? = null,
|
||||||
val type: kotlin.String?,
|
val type: kotlin.String? = null,
|
||||||
val message: kotlin.String?
|
val message: kotlin.String? = null
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -13,11 +13,13 @@ package io.swagger.client.models
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A category for a pet
|
* A category for a pet
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
data class Category (
|
data class Category (
|
||||||
val id: kotlin.Long?,
|
val id: kotlin.Long? = null,
|
||||||
val name: kotlin.String?
|
val name: kotlin.String? = null
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -13,20 +13,29 @@ package io.swagger.client.models
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An order for a pets from the pet store
|
* An order for a pets from the pet store
|
||||||
* @param id
|
* @param id
|
||||||
* @param petId
|
* @param petId
|
||||||
* @param quantity
|
* @param quantity
|
||||||
* @param shipDate
|
* @param shipDate
|
||||||
* @param status Order Status
|
* @param status Order Status
|
||||||
* @param complete
|
* @param complete
|
||||||
*/
|
*/
|
||||||
data class Order (
|
data class Order (
|
||||||
val id: kotlin.Long?,
|
val id: kotlin.Long? = null,
|
||||||
val petId: kotlin.Long?,
|
val petId: kotlin.Long? = null,
|
||||||
val quantity: kotlin.Int?,
|
val quantity: kotlin.Int? = null,
|
||||||
val shipDate: java.time.LocalDateTime?,
|
val shipDate: java.time.LocalDateTime? = null,
|
||||||
/* Order Status */
|
/* Order Status */
|
||||||
val status: kotlin.String?,
|
val status: Order.Status? = null,
|
||||||
val complete: kotlin.Boolean?
|
val complete: kotlin.Boolean? = null
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
enum class Status(val value: kotlin.String) {
|
||||||
|
placed("placed"),
|
||||||
|
approved("approved"),
|
||||||
|
delivered("delivered");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -15,20 +15,29 @@ import io.swagger.client.models.Category
|
|||||||
import io.swagger.client.models.Tag
|
import io.swagger.client.models.Tag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pet for sale in the pet store
|
* A pet for sale in the pet store
|
||||||
* @param id
|
* @param id
|
||||||
* @param category
|
* @param category
|
||||||
* @param name
|
* @param name
|
||||||
* @param photoUrls
|
* @param photoUrls
|
||||||
* @param tags
|
* @param tags
|
||||||
* @param status pet status in the store
|
* @param status pet status in the store
|
||||||
*/
|
*/
|
||||||
data class Pet (
|
data class Pet (
|
||||||
val id: kotlin.Long?,
|
val name: kotlin.String,
|
||||||
val category: Category?,
|
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||||
val name: kotlin.String,
|
val id: kotlin.Long? = null,
|
||||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
val category: Category? = null,
|
||||||
val tags: kotlin.collections.List<Tag>?,
|
val tags: kotlin.collections.List<Tag>? = null,
|
||||||
/* pet status in the store */
|
/* 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -13,11 +13,13 @@ package io.swagger.client.models
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tag for a pet
|
* A tag for a pet
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
data class Tag (
|
data class Tag (
|
||||||
val id: kotlin.Long?,
|
val id: kotlin.Long? = null,
|
||||||
val name: kotlin.String?
|
val name: kotlin.String? = null
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -13,24 +13,26 @@ package io.swagger.client.models
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A User who is purchasing from the pet store
|
* A User who is purchasing from the pet store
|
||||||
* @param id
|
* @param id
|
||||||
* @param username
|
* @param username
|
||||||
* @param firstName
|
* @param firstName
|
||||||
* @param lastName
|
* @param lastName
|
||||||
* @param email
|
* @param email
|
||||||
* @param password
|
* @param password
|
||||||
* @param phone
|
* @param phone
|
||||||
* @param userStatus User Status
|
* @param userStatus User Status
|
||||||
*/
|
*/
|
||||||
data class User (
|
data class User (
|
||||||
val id: kotlin.Long?,
|
val id: kotlin.Long? = null,
|
||||||
val username: kotlin.String?,
|
val username: kotlin.String? = null,
|
||||||
val firstName: kotlin.String?,
|
val firstName: kotlin.String? = null,
|
||||||
val lastName: kotlin.String?,
|
val lastName: kotlin.String? = null,
|
||||||
val email: kotlin.String?,
|
val email: kotlin.String? = null,
|
||||||
val password: kotlin.String?,
|
val password: kotlin.String? = null,
|
||||||
val phone: kotlin.String?,
|
val phone: kotlin.String? = null,
|
||||||
/* User Status */
|
/* User Status */
|
||||||
val userStatus: kotlin.Int?
|
val userStatus: kotlin.Int? = null
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -9,7 +9,7 @@ class EvaluateTest : ShouldSpec() {
|
|||||||
init {
|
init {
|
||||||
should("query against pet statuses") {
|
should("query against pet statuses") {
|
||||||
val api = PetApi()
|
val api = PetApi()
|
||||||
val results = api.findPetsByStatus(listOf("available", "pending"))
|
val results = api.findPetsByStatus(listOf("sold"))
|
||||||
|
|
||||||
results.size should beGreaterThan(1)
|
results.size should beGreaterThan(1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user