diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache index eb4c35341933..b9bb49eae25a 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache @@ -176,7 +176,7 @@ import {{packageName}}.infrastructure.ITransformForStorage override fun deserialize(decoder: Decoder): {{nameInPascalCase}} { val value = decoder.decodeSerializableValue({{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}kotlin.String{{/isContainer}}.serializer()) - return {{nameInPascalCase}}.values().firstOrNull { it.value == value } + return {{nameInPascalCase}}.entries.firstOrNull { it.value == value } ?: {{nameInPascalCase}}.{{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}} } @@ -360,14 +360,14 @@ import {{packageName}}.infrastructure.ITransformForStorage {{#isEnum}} {{#required}} // validate the required field `{{{baseName}}}` - require({{{datatypeWithEnum}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { + require({{{datatypeWithEnum}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { String.format("Expected the field `{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}` to be valid `{{{datatypeWithEnum}}}` enum value in the JSON string but got `%s`", jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].toString()) } {{/required}} {{^required}} // validate the optional field `{{{baseName}}}` if (jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"] != null && !jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].isJsonNull) { - require({{{datatypeWithEnum}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { + require({{{datatypeWithEnum}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { String.format("Expected the field `{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}` to be valid `{{{datatypeWithEnum}}}` enum value in the JSON string but got `%s`", jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].toString()) } } @@ -376,14 +376,14 @@ import {{packageName}}.infrastructure.ITransformForStorage {{#isEnumRef}} {{#required}} // validate the required field `{{{baseName}}}` - require({{{dataType}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { + require({{{dataType}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { String.format("Expected the field `{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}` to be valid `{{{dataType}}}` enum value in the JSON string but got `%s`", jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].toString()) } {{/required}} {{^required}} // validate the optional field `{{{baseName}}}` if (jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"] != null && !jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].isJsonNull) { - require({{{dataType}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { + require({{{dataType}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) { String.format("Expected the field `{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}` to be valid `{{{dataType}}}` enum value in the JSON string but got `%s`", jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].toString()) } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache index 3c2fdebf0b3d..054c54456cfc 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache @@ -109,7 +109,7 @@ import kotlinx.serialization.* {{^jackson}} {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun decode(data: kotlin.Any?): {{classname}}? = data?.let { val normalizedData = "$it".lowercase() - values().firstOrNull { value -> + entries.firstOrNull { value -> it == value || normalizedData == "$value".lowercase() } } @@ -127,7 +127,7 @@ import kotlinx.serialization.* {{/isNullable}} } val normalizedData = "$data".lowercase() - return values().firstOrNull { value -> + return entries.firstOrNull { value -> data == value || normalizedData == "$value".lowercase() }{{#isNullable}}{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}} ?: {{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}} @@ -142,7 +142,7 @@ internal object {{classname}}Serializer : KSerializer<{{classname}}> { override fun deserialize(decoder: Decoder): {{classname}} { val value = decoder.decodeSerializableValue({{{dataType}}}.serializer()) - return {{classname}}.values().firstOrNull { it.value == value } + return {{classname}}.entries.firstOrNull { it.value == value } {{#isString}} ?: {{classname}}.{{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}} {{/isString}} @@ -162,7 +162,7 @@ internal object {{classname}}Serializer : KSerializer<{{classname}}> { override fun deserialize(decoder: Decoder): {{classname}} { val value = decoder.decodeSerializableValue({{{dataType}}}.serializer()) - return {{classname}}.values().firstOrNull { it.value == value } + return {{classname}}.entries.firstOrNull { it.value == value } ?: throw IllegalArgumentException("Unknown enum value: $value") } diff --git a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt index 865fba881ff6..7b705f3e78d7 100644 --- a/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt +++ b/samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt @@ -57,7 +57,7 @@ enum class ApiStringEnumRef(val value: kotlin.String) { */ fun decode(data: kotlin.Any?): ApiStringEnumRef? = data?.let { val normalizedData = "$it".lowercase() - values().firstOrNull { value -> + entries.firstOrNull { value -> it == value || normalizedData == "$value".lowercase() } } diff --git a/samples/client/echo_api/kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt b/samples/client/echo_api/kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt index 3c149c23ea07..c046584c1f42 100644 --- a/samples/client/echo_api/kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt +++ b/samples/client/echo_api/kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt @@ -67,7 +67,7 @@ enum class StringEnumRef(@get:JsonValue val value: kotlin.String) { throw IllegalArgumentException("Value for StringEnumRef cannot be null") } val normalizedData = "$data".lowercase() - return values().firstOrNull { value -> + return entries.firstOrNull { value -> data == value || normalizedData == "$value".lowercase() } ?: unknown_default_open_api diff --git a/samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt b/samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt index 3c149c23ea07..c046584c1f42 100644 --- a/samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt +++ b/samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt @@ -67,7 +67,7 @@ enum class StringEnumRef(@get:JsonValue val value: kotlin.String) { throw IllegalArgumentException("Value for StringEnumRef cannot be null") } val normalizedData = "$data".lowercase() - return values().firstOrNull { value -> + return entries.firstOrNull { value -> data == value || normalizedData == "$value".lowercase() } ?: unknown_default_open_api diff --git a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt index d9971985a7ea..0dd67a0e55a4 100644 --- a/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt +++ b/samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt @@ -55,7 +55,7 @@ enum class ApiStringEnumRef(val value: kotlin.String) { */ fun decode(data: kotlin.Any?): ApiStringEnumRef? = data?.let { val normalizedData = "$it".lowercase() - values().firstOrNull { value -> + entries.firstOrNull { value -> it == value || normalizedData == "$value".lowercase() } } diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/Code.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/Code.kt index f6cc6eb35a02..ea14b4386a87 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/Code.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/Code.kt @@ -54,7 +54,7 @@ enum class Code(val value: kotlin.Int) { */ fun decode(data: kotlin.Any?): Code? = data?.let { val normalizedData = "$it".lowercase() - values().firstOrNull { value -> + entries.firstOrNull { value -> it == value || normalizedData == "$value".lowercase() } } diff --git a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/StringCode.kt b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/StringCode.kt index f2e6177461ee..1f54464f3934 100644 --- a/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/StringCode.kt +++ b/samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/StringCode.kt @@ -54,7 +54,7 @@ enum class StringCode(val value: kotlin.String) { */ fun decode(data: kotlin.Any?): StringCode? = data?.let { val normalizedData = "$it".lowercase() - values().firstOrNull { value -> + entries.firstOrNull { value -> it == value || normalizedData == "$value".lowercase() } } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Order.kt index 34b443ec439e..fd49ea4ab20f 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Order.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Order.kt @@ -81,7 +81,7 @@ data class Order ( override fun deserialize(decoder: Decoder): Status { val value = decoder.decodeSerializableValue(kotlin.String.serializer()) - return Status.values().firstOrNull { it.value == value } + return Status.entries.firstOrNull { it.value == value } ?: Status.unknown_default_open_api } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Pet.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Pet.kt index 96cdd5295ca6..3a130634e2e1 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Pet.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Pet.kt @@ -83,7 +83,7 @@ data class Pet ( override fun deserialize(decoder: Decoder): Status { val value = decoder.decodeSerializableValue(kotlin.String.serializer()) - return Status.values().firstOrNull { it.value == value } + return Status.entries.firstOrNull { it.value == value } ?: Status.unknown_default_open_api } diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiOrder.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiOrder.kt index e5bb80c0639e..a07fbb2b2ee4 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiOrder.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiOrder.kt @@ -135,7 +135,7 @@ data class ApiOrder ( } // validate the optional field `status` if (jsonObj["status"] != null && !jsonObj["status"].isJsonNull) { - require(Status.values().any { it.value == jsonObj["status"].asString }) { + require(Status.entries.any { it.value == jsonObj["status"].asString }) { String.format("Expected the field `status` to be valid `Status` enum value in the JSON string but got `%s`", jsonObj["status"].toString()) } } diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt index 7d6987037d10..b831ef286ed8 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt @@ -183,7 +183,7 @@ data class ApiPet ( } // validate the optional field `status` if (jsonObj["status"] != null && !jsonObj["status"].isJsonNull) { - require(Status.values().any { it.value == jsonObj["status"].asString }) { + require(Status.entries.any { it.value == jsonObj["status"].asString }) { String.format("Expected the field `status` to be valid `Status` enum value in the JSON string but got `%s`", jsonObj["status"].toString()) } } diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt index df2f6ee56f2c..b324a4e24559 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/models/PetEnum.kt @@ -62,7 +62,7 @@ enum class PetEnum(val value: kotlin.String) { */ fun decode(data: kotlin.Any?): PetEnum? = data?.let { val normalizedData = "$it".lowercase() - values().firstOrNull { value -> + entries.firstOrNull { value -> it == value || normalizedData == "$value".lowercase() } } @@ -74,7 +74,7 @@ internal object PetEnumSerializer : KSerializer { override fun deserialize(decoder: Decoder): PetEnum { val value = decoder.decodeSerializableValue(kotlin.String.serializer()) - return PetEnum.values().firstOrNull { it.value == value } + return PetEnum.entries.firstOrNull { it.value == value } ?: PetEnum.UNKNOWN_DEFAULT_OPEN_API }