For cases where enum in responses of server can change enum values and we should not fail all parsing we need to implement support of https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#coercing-input-values
for it we add into gradle plugin spec configuration new variable - enumFallbackNull: Boolean, and if it true we should generate for all enums default value (if spec already have default value - use it. if no default value - use null).
as result we got support of successful serialization of response:
{
"type": "unknown"
}
for scheme:
components:
schemas:
Color:
type: string
enum:
- black
- white
- red
- green
- blue
with generated schema:
@Serializable
data class Color(val type: ColorType? = null)
For cases where enum in responses of server can change enum values and we should not fail all parsing we need to implement support of https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#coercing-input-values for it we add into gradle plugin spec configuration new variable -
enumFallbackNull: Boolean
, and if it true we should generate for all enums default value (if spec already have default value - use it. if no default value - usenull
).as result we got support of successful serialization of response:
for scheme:
with generated schema:
and json config: