Skip to content

Commit e555956

Browse files
committed
[Kotlin][Client] Migrate Enum.values() to Enum.entities
1 parent 6f211a2 commit e555956

File tree

13 files changed

+21
-21
lines changed

13 files changed

+21
-21
lines changed

modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ import {{packageName}}.infrastructure.ITransformForStorage
176176

177177
override fun deserialize(decoder: Decoder): {{nameInPascalCase}} {
178178
val value = decoder.decodeSerializableValue({{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}kotlin.String{{/isContainer}}.serializer())
179-
return {{nameInPascalCase}}.values().firstOrNull { it.value == value }
179+
return {{nameInPascalCase}}.entries.firstOrNull { it.value == value }
180180
?: {{nameInPascalCase}}.{{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}}
181181
}
182182

@@ -360,14 +360,14 @@ import {{packageName}}.infrastructure.ITransformForStorage
360360
{{#isEnum}}
361361
{{#required}}
362362
// validate the required field `{{{baseName}}}`
363-
require({{{datatypeWithEnum}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
363+
require({{{datatypeWithEnum}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
364364
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())
365365
}
366366
{{/required}}
367367
{{^required}}
368368
// validate the optional field `{{{baseName}}}`
369369
if (jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"] != null && !jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].isJsonNull) {
370-
require({{{datatypeWithEnum}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
370+
require({{{datatypeWithEnum}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
371371
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())
372372
}
373373
}
@@ -376,14 +376,14 @@ import {{packageName}}.infrastructure.ITransformForStorage
376376
{{#isEnumRef}}
377377
{{#required}}
378378
// validate the required field `{{{baseName}}}`
379-
require({{{dataType}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
379+
require({{{dataType}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
380380
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())
381381
}
382382
{{/required}}
383383
{{^required}}
384384
// validate the optional field `{{{baseName}}}`
385385
if (jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"] != null && !jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].isJsonNull) {
386-
require({{{dataType}}}.values().any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
386+
require({{{dataType}}}.entries.any { it.value == jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].asString }) {
387387
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())
388388
}
389389
}

modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import kotlinx.serialization.*
109109
{{^jackson}}
110110
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun decode(data: kotlin.Any?): {{classname}}? = data?.let {
111111
val normalizedData = "$it".lowercase()
112-
values().firstOrNull { value ->
112+
entries.firstOrNull { value ->
113113
it == value || normalizedData == "$value".lowercase()
114114
}
115115
}
@@ -127,7 +127,7 @@ import kotlinx.serialization.*
127127
{{/isNullable}}
128128
}
129129
val normalizedData = "$data".lowercase()
130-
return values().firstOrNull { value ->
130+
return entries.firstOrNull { value ->
131131
data == value || normalizedData == "$value".lowercase()
132132
}{{#isNullable}}{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}
133133
?: {{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}
@@ -142,7 +142,7 @@ internal object {{classname}}Serializer : KSerializer<{{classname}}> {
142142

143143
override fun deserialize(decoder: Decoder): {{classname}} {
144144
val value = decoder.decodeSerializableValue({{{dataType}}}.serializer())
145-
return {{classname}}.values().firstOrNull { it.value == value }
145+
return {{classname}}.entries.firstOrNull { it.value == value }
146146
{{#isString}}
147147
?: {{classname}}.{{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}}
148148
{{/isString}}
@@ -162,7 +162,7 @@ internal object {{classname}}Serializer : KSerializer<{{classname}}> {
162162

163163
override fun deserialize(decoder: Decoder): {{classname}} {
164164
val value = decoder.decodeSerializableValue({{{dataType}}}.serializer())
165-
return {{classname}}.values().firstOrNull { it.value == value }
165+
return {{classname}}.entries.firstOrNull { it.value == value }
166166
?: throw IllegalArgumentException("Unknown enum value: $value")
167167
}
168168

samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum class ApiStringEnumRef(val value: kotlin.String) {
5757
*/
5858
fun decode(data: kotlin.Any?): ApiStringEnumRef? = data?.let {
5959
val normalizedData = "$it".lowercase()
60-
values().firstOrNull { value ->
60+
entries.firstOrNull { value ->
6161
it == value || normalizedData == "$value".lowercase()
6262
}
6363
}

samples/client/echo_api/kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum class StringEnumRef(@get:JsonValue val value: kotlin.String) {
6767
throw IllegalArgumentException("Value for StringEnumRef cannot be null")
6868
}
6969
val normalizedData = "$data".lowercase()
70-
return values().firstOrNull { value ->
70+
return entries.firstOrNull { value ->
7171
data == value || normalizedData == "$value".lowercase()
7272
}
7373
?: unknown_default_open_api

samples/client/echo_api/kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/models/StringEnumRef.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum class StringEnumRef(@get:JsonValue val value: kotlin.String) {
6767
throw IllegalArgumentException("Value for StringEnumRef cannot be null")
6868
}
6969
val normalizedData = "$data".lowercase()
70-
return values().firstOrNull { value ->
70+
return entries.firstOrNull { value ->
7171
data == value || normalizedData == "$value".lowercase()
7272
}
7373
?: unknown_default_open_api

samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ enum class ApiStringEnumRef(val value: kotlin.String) {
5555
*/
5656
fun decode(data: kotlin.Any?): ApiStringEnumRef? = data?.let {
5757
val normalizedData = "$it".lowercase()
58-
values().firstOrNull { value ->
58+
entries.firstOrNull { value ->
5959
it == value || normalizedData == "$value".lowercase()
6060
}
6161
}

samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/Code.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum class Code(val value: kotlin.Int) {
5454
*/
5555
fun decode(data: kotlin.Any?): Code? = data?.let {
5656
val normalizedData = "$it".lowercase()
57-
values().firstOrNull { value ->
57+
entries.firstOrNull { value ->
5858
it == value || normalizedData == "$value".lowercase()
5959
}
6060
}

samples/client/others/kotlin-integer-enum/src/main/kotlin/org/openapitools/client/models/StringCode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum class StringCode(val value: kotlin.String) {
5454
*/
5555
fun decode(data: kotlin.Any?): StringCode? = data?.let {
5656
val normalizedData = "$it".lowercase()
57-
values().firstOrNull { value ->
57+
entries.firstOrNull { value ->
5858
it == value || normalizedData == "$value".lowercase()
5959
}
6060
}

samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Order.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ data class Order (
8181

8282
override fun deserialize(decoder: Decoder): Status {
8383
val value = decoder.decodeSerializableValue(kotlin.String.serializer())
84-
return Status.values().firstOrNull { it.value == value }
84+
return Status.entries.firstOrNull { it.value == value }
8585
?: Status.unknown_default_open_api
8686
}
8787

samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/models/Pet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ data class Pet (
8383

8484
override fun deserialize(decoder: Decoder): Status {
8585
val value = decoder.decodeSerializableValue(kotlin.String.serializer())
86-
return Status.values().firstOrNull { it.value == value }
86+
return Status.entries.firstOrNull { it.value == value }
8787
?: Status.unknown_default_open_api
8888
}
8989

0 commit comments

Comments
 (0)