Conversation
The Java enum templates wrapped every enum value with `{{dataType}}.valueOf(...)`.
That method does not exist for every possible data type (e.g. `BigDecimal` has no
`BigDecimal.valueOf(BigDecimal)` and `Object` has no `valueOf` at all), producing
code that does not compile.
`valueOf()` is now only emitted for types where it actually exists, i.e. it is
skipped for `isUri`, `isNumeric` and `isFreeFormObject` enum values. The wrapper
was originally introduced to fix Boolean enums (OpenAPITools#19815), which keeps working.
Templates updated:
- Java/modelInnerEnum.mustache
- Java/libraries/microprofile/enumClass.mustache
- JavaJaxRS/{spec,cxf,cxf-cdi,cxf-ext}/enumClass.mustache
- java-helidon/client/libraries/{mp,se}/enumClass.mustache
- java-helidon/server/libraries/mp/enumClass.mustache
Test coverage added to the petstore test specs: a numeric enum (`Order.paymentMethod`),
a string enum with `additionalProperties: false` (`Order.OrderStatus`) and integer /
double form enum parameters.
Fixes OpenAPITools#20188
Co-authored-by: Timon Link <timon.link@sbroker.de>
Co-authored-by: Martin <2026226+martin-mfg@users.noreply.github.com>
This was referenced Sep 2, 2026
Contributor
There was a problem hiding this comment.
1 issue found across 265 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/java-helidon-client/v3/mp/src/main/java/org/openapitools/client/model/Order.java">
<violation number="1" location="samples/client/petstore/java-helidon-client/v3/mp/src/main/java/org/openapitools/client/model/Order.java:66">
P2: The newly added numeric inner enum PaymentMethodEnum cannot round-trip its wire value. Its constant names NUMBER_1/NUMBER_2 diverge from the spec values "1"/"2", and the java-helidon enumClass.mustache template emits no @JsonValue/@JsonCreator, so Jackson's name-based default serializes PaymentMethodEnum.NUMBER_1 as "NUMBER_1" and throws on deserializing "1". The standalone numeric enum OuterEnumInteger in the same sample carries @JsonValue/@JsonCreator and round-trips correctly, so the two are inconsistent. Add the @JsonValue/@JsonCreator (fromValue) pattern to the inner enum template, matching enumClass/standalone enums, so the new numeric enum test case is functional rather than compile-only.</violation>
</file>
Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
Re-trigger cubic
jorgerod
marked this pull request as draft
September 2, 2026 12:54
- Exclude `isUuid` from the `valueOf()` wrapper. `AbstractJavaCodegen.toEnumValue`
already returns `UUID.fromString("...")` for UUID enums, so the templates were
emitting `UUID.valueOf(UUID.fromString(...))`, which does not compile. This is
the same class of bug this PR fixes and mirrors the existing `isUri` handling.
Regenerating all 800 samples produces no output change, as no test fixture
currently declares a UUID enum.
- Revert the Ameba version change in the Crystal sample. It was edited in the
generated `shard.yml` only, while the value comes from `crystal/shard.mustache`,
so it would have been reverted by `Samples up-to-date`. The Ameba `1.7.0-dev`
resolution failure is a pre-existing breakage unrelated to this PR.
- Drop the `FakeApiTest.java` entries that were added to `.openapi-generator/FILES`.
The generator never overwrites existing test files, so those entries are not
reproducible on regeneration and would have failed `Samples up-to-date`.
jorgerod
marked this pull request as ready for review
September 2, 2026 15:17
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 292 files
Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
Re-trigger cubic
…withXml
Two additional compile failures surfaced by the new PaymentMethodEnum (BigDecimal)
and OrderStatusEnum (Object) test fixtures, both unrelated to the valueOf() fix
but exposed by the same regression tests:
1. JSON-B serializer: `generator.write(obj.value)` requires an overload matching
the static type of `obj.value`. `jakarta.json.stream.JsonGenerator` has no
`write(Object)` overload, so any enum backed by a free-form/Object dataType
(e.g. OrderStatusEnum, `additionalProperties: false`) failed to compile with:
no suitable method found for write(java.lang.Object)
Fixed by writing `String.valueOf(obj.value)` when `isFreeFormObject`, in every
template with this JSON-B `Serializer` (Java, java-helidon client/server,
microprofile, for both inner and standalone enums).
2. `@XmlEnumValue`: the annotation requires a compile-time constant `String`.
The existing quoting logic only handles `isInteger`/`isDouble`/`isLong`/
`isFloat`. For any other numeric format (plain `type: number`, dataType
`BigDecimal`), `{{{value}}}` is `new BigDecimal("1")` — an expression, not a
constant — which is invalid as an annotation argument:
expression not allowed as annotation value
The same applies to `isUri` (`URI.create(...)`) and `isUuid`
(`UUID.fromString(...)`), which were never exercised with `withXml` before.
Fixed by omitting `@XmlEnumValue` for `isUri`/`isUuid`/`isNumber` enums;
JAXB falls back to the enum constant name, which still compiles.
Regenerating all 800 samples changes only the 3 previously-broken outputs
(microprofile-rest-client, microprofile-rest-client-3.0, resttemplate-withXml);
all three now compile (`mvn compile`).
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 23 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
2 of 3 tasks
Resolve conflicts: take master's javaStringLiteral-based @XmlEnumValue and keep this PR's valueOf guards (^isUuid ^isNumeric ^isFreeFormObject) in the Java/microprofile/JavaJaxRS/helidon/micronaut enum templates. Restored master's @nullable handling in regenerated resttemplate samples while keeping the new enum_form_integer/enum_form_double parameters.
jorgerod
marked this pull request as draft
September 24, 2026 12:30
The shared Java/modelEnum.mustache and Java/modelInnerEnum.mustache are consumed by the restclient, resttemplate and webclient libraries only; every other Java generator uses its own copies under libraries/. This reverts all other template changes (microprofile, native, JaxRS, helidon, micronaut, okhttp-gson, Groovy), the shared petstore test-spec changes and all out-of-scope sample churn so the PR stays reviewable and CI-green. Verification for the remaining two templates is covered by the generated samples of the in-scope libraries when regenerated, and by the existing model enum unit tests.
The previous refactor left '(value)' outside the isString section, so non-string enums rendered invalid code like 'if ((value)|| ...)' (OuterEnumInteger) or 'if (b.value.equals)' (StringEnumRef). Rewritten with mutually-exclusive mustache sections: string branch keeps master's equals/[IgnoreCase]/(value), non-string renders equals or compareTo for numeric types, and free-form object enums use equals.
jorgerod
marked this pull request as ready for review
September 24, 2026 15:18
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)Technical Committee
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)
Description
This supersedes #21055, which had become unmergeable (conflicting with
master) and whose author is no longer available. As requested by @wing328 (comment), this is a fresh PR based on the currentmaster. Full credit to @timon-sbr and @martin-mfg (kept as co-authors of the original commit).Scope update: after an early review, the PR was narrowed down to the Java
restclient,resttemplateandwebclientlibraries. Those are the only generators that consume the sharedJava/modelEnum.mustacheandJava/modelInnerEnum.mustachetemplates; every other Java generator (microprofile, native, okhttp-gson, helidon, micronaut, JaxRS/cxf, Groovy...) uses its own copies underJava/libraries/, which are unchanged in this PR.Problem
In
Java/modelInnerEnum.mustache, the Java enum templates wrapped every enum value with{{dataType}}.valueOf(...):valueOf()is not available for every possible data type, which produces code that does not compile:BigDecimalhas noBigDecimal.valueOf(BigDecimal)— e.g.type: numberenums.UUIDhas novalueOfeither.AbstractJavaCodegen.toEnumValuealready returnsUUID.fromString("...")for UUID enums, so the template emittedUUID.valueOf(UUID.fromString(...)). This mirrorsURI, which was already excluded.Objecthas novalueOfat all — e.g. an inlineenum:without an explicittype, or atype: stringenum withadditionalProperties: false, which currently map toObject:Fix
Two changes in each of the two shared templates:
Constructor (
modelInnerEnum.mustacheonly):valueOf()is now only emitted for types that actually provide it, i.e. it is skipped forisUri,isUuid,isNumericandisFreeFormObject:(As a visible consequence, numeric enums now emit
NUMBER_1(1)instead ofInteger.valueOf(1);Boolean/Stringkeep usingvalueOf(), so this is non-breaking. The wrapper was originally added to fix Boolean enums, [JAVA] fix inner enums of booleans #19815.)fromValue(both templates): numeric enums (isNumber, e.g.BigDecimal) are now compared withcompareTo()instead ofequals(), becauseBigDecimal.equalsis scale-sensitive (1!=1.0numerically identical values would throwIllegalArgumentExceptionat deserialization):For free-form-object enums (
isFreeFormObject), the rawequals()comparison is kept.JSON-B serializer (both templates):
generator.write(obj.value)does not compile for enums backed byObject(jakarta.json.stream.JsonGeneratorhas nowrite(Object)overload); the value is now written asString.valueOf(obj.value)whenisFreeFormObject.Only
modelEnum.mustacheandmodelInnerEnum.mustache(the shared templates used byrestclient,resttemplateandwebclient) are modified.Test coverage
The shared petstore test spec (
petstore-with-fake-endpoints-models-for-testing.yaml) gained:Order.paymentMethod— a numeric (type: number) enum, covering theBigDecimalcase.Order.OrderStatus— atype: stringenum withadditionalProperties: false, covering theObjectcase.enum_form_integer/enum_form_doubleform parameters ontestEnumParameters.Samples were regenerated for the in-scope generators; all changes are limited to generated
EnumTestmodel files.This PR closes #20188 and replaces #21055.