mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 14:57:13 +00:00
kotlin-spring: fix exception thrown in enum.forValue (#21622)
* kotlin-spring: fix exception thrown in enum.forValue * update samples
This commit is contained in:
@@ -41,7 +41,8 @@ data class ApiError(
|
||||
@JvmStatic
|
||||
@JsonCreator
|
||||
fun forValue(value: kotlin.Int): ErrorCode {
|
||||
return values().first{it -> it.value == value}
|
||||
return values().firstOrNull{it -> it.value == value}
|
||||
?: throw IllegalArgumentException("Unexpected value '$value' for enum 'ApiError'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ enum class ReasonCode(@get:JsonValue val value: kotlin.Int) {
|
||||
@JvmStatic
|
||||
@JsonCreator
|
||||
fun forValue(value: kotlin.Int): ReasonCode {
|
||||
return values().first{it -> it.value == value}
|
||||
return values().firstOrNull{it -> it.value == value}
|
||||
?: throw IllegalArgumentException("Unexpected value '$value' for enum 'ReasonCode'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user