Bug Report Checklist
Description
Since version 7.19.0, the generated @JsonCreator decode() method for non-nullable Kotlin enums throws IllegalArgumentException on unknown values. In 7.18.0 and earlier, the same method returned null, allowing callers to handle unknown enum values gracefully (e.g. from forward-compatible APIs where new enum values may be added server-side before clients update their specs).
This is a silent breaking change for any consumer that relied on decode() returning null for unrecognized values. There was no mention of this behavioral change in the release notes.
openapi-generator version
Regression introduced in 7.19.0 (works correctly in 7.18.0). Still present in 7.21.0.
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
title: Test
version: "1.0"
paths: {}
components:
schemas:
ChannelType:
type: string
enum:
- ANDROID
- IOS
- WEB
Generation Details
openapi-generator generate -g kotlin -i spec.yaml -o out \
--additional-properties=library=jvm-spring
Steps to reproduce
- Generate with openapi-generator 7.18.0 →
ChannelType.decode("UNKNOWN") returns null
- Generate with openapi-generator 7.19.0 →
ChannelType.decode("UNKNOWN") throws IllegalArgumentException
Expected: decode() returns null for unknown values (or at minimum, the breaking change is documented and opt-in).
Actual: decode() throws, breaking any downstream code that handled null gracefully.
Related issues/PRs
Suggest a fix
Either:
- Revert to the previous behavior (return
null) — this requires removing @JsonCreator from decode(), otherwise there's an inconsistency where Jackson deserialization throws on unknown values but calling decode() directly would return null. Without @JsonCreator, Jackson's default enum handling applies and decode() remains a standalone utility.
- Make the throwing behavior opt-in via a configuration flag
- This changes the public API contract of generated models — if kept intentionally, it warrants a major version bump (8.0.0), not a patch/minor release, since consumers rely on the return type and nullability semantics of generated code.
Bug Report Checklist
Description
Since version 7.19.0, the generated
@JsonCreator decode()method for non-nullable Kotlin enums throwsIllegalArgumentExceptionon unknown values. In 7.18.0 and earlier, the same method returnednull, allowing callers to handle unknown enum values gracefully (e.g. from forward-compatible APIs where new enum values may be added server-side before clients update their specs).This is a silent breaking change for any consumer that relied on
decode()returningnullfor unrecognized values. There was no mention of this behavioral change in the release notes.openapi-generator version
Regression introduced in 7.19.0 (works correctly in 7.18.0). Still present in 7.21.0.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
ChannelType.decode("UNKNOWN")returnsnullChannelType.decode("UNKNOWN")throwsIllegalArgumentExceptionExpected:
decode()returnsnullfor unknown values (or at minimum, the breaking change is documented and opt-in).Actual:
decode()throws, breaking any downstream code that handlednullgracefully.Related issues/PRs
Suggest a fix
Either:
null) — this requires removing@JsonCreatorfromdecode(), otherwise there's an inconsistency where Jackson deserialization throws on unknown values but callingdecode()directly would returnnull. Without@JsonCreator, Jackson's default enum handling applies anddecode()remains a standalone utility.