mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 04:37:12 +00:00
* [kotlin-spring] add a Spring type converter for enum values #21564 * [kotlin-spring] simplify unit test for inner enum converter * update samples * code review feedback; move containsEnums to ModelUtils * code review feedback; provide comment for generated EnumConverterConfiguration.kt * update samples --------- Co-authored-by: Chris Gual <cgual@omnidian.com>
This commit is contained in:
@@ -9,5 +9,6 @@ settings.gradle
|
||||
src/main/kotlin/org/openapitools/api/ApiUtil.kt
|
||||
src/main/kotlin/org/openapitools/api/DefaultApi.kt
|
||||
src/main/kotlin/org/openapitools/api/Exceptions.kt
|
||||
src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt
|
||||
src/main/kotlin/org/openapitools/model/ApiError.kt
|
||||
src/main/kotlin/org/openapitools/model/ReasonCode.kt
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.openapitools.configuration
|
||||
|
||||
import org.openapitools.model.ReasonCode
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.core.convert.converter.Converter
|
||||
|
||||
/**
|
||||
* This class provides Spring Converter beans for the enum models in the OpenAPI specification.
|
||||
*
|
||||
* By default, Spring only converts primitive types to enums using Enum::valueOf, which can prevent
|
||||
* correct conversion if the OpenAPI specification is using an `enumPropertyNaming` other than
|
||||
* `original` or the specification has an integer enum.
|
||||
*/
|
||||
@Configuration(value = "org.openapitools.configuration.enumConverterConfiguration")
|
||||
class EnumConverterConfiguration {
|
||||
|
||||
@Bean(name = ["org.openapitools.configuration.EnumConverterConfiguration.reasonCodeConverter"])
|
||||
fun reasonCodeConverter(): Converter<kotlin.Int, ReasonCode> {
|
||||
return object: Converter<kotlin.Int, ReasonCode> {
|
||||
override fun convert(source: kotlin.Int): ReasonCode = ReasonCode.forValue(source)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user