Skip to content

fix(java): fix oneOf interface ignoring useJakartaEe for @Generated a… - #24893

Open
anupamchaubey wants to merge 1 commit into
OpenAPITools:masterfrom
anupamchaubey:fix-java-oneof-generated-annotation
Open

fix(java): fix oneOf interface ignoring useJakartaEe for @Generated a…#24893
anupamchaubey wants to merge 1 commit into
OpenAPITools:masterfrom
anupamchaubey:fix-java-oneof-generated-annotation

Conversation

@anupamchaubey

@anupamchaubey anupamchaubey commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Fixes an issue where the generated oneOf interface in Java generators ignores the useJakartaEe=true configuration and hardcodes javax.annotation.Generated instead of using the dynamic javaxPackage.

Root cause: The synthetic oneOf interface model map created in DefaultCodegen.java was missing the javaxPackage context property.

Fix: Injected javaxPackage into the oneOf model map entries (objsValue.put("javaxPackage", ...)) so templates properly receive jakarta when useJakartaEe=true is enabled.

Fixes #24889

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    /cc @wing328 @cbornet @jmini

Summary by cubic

Fixes the Java generator ignoring useJakartaEe=true for the oneOf interface's @Generated annotation. It previously hardcoded javax.annotation.Generated; now it follows the configured javaxPackage and emits jakarta.annotation.Generated when enabled. Fixes #24889.

Written for commit f004b7f. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

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="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java:606">
P2: This line is redundant: `objsValue.putAll(additionalProperties)` two lines above already copies `javaxPackage` into `objsValue` for Java generators, because `applyJavaxPackage()`/`applyJakartaPackage()` write it into `additionalProperties` during `processOpts()`, before `postProcessAllModels()` runs. The new `put` overwrites the same key with the same value, so it cannot change the template context for Java. If the oneOf interface was still rendering `javax`, this line does not fix it — the real cause is likely how the oneOf template consumes the model map entries, not a missing context property. Verify the actual rendering path or remove this no-op.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

objsValue.put("classname", cm.classname);
objsValue.putAll(additionalProperties);
objs.put(cm.name, objsValue);
objsValue.put("javaxPackage", additionalProperties.getOrDefault("javaxPackage", "javax"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This line is redundant: objsValue.putAll(additionalProperties) two lines above already copies javaxPackage into objsValue for Java generators, because applyJavaxPackage()/applyJakartaPackage() write it into additionalProperties during processOpts(), before postProcessAllModels() runs. The new put overwrites the same key with the same value, so it cannot change the template context for Java. If the oneOf interface was still rendering javax, this line does not fix it — the real cause is likely how the oneOf template consumes the model map entries, not a missing context property. Verify the actual rendering path or remove this no-op.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java, line 606:

<comment>This line is redundant: `objsValue.putAll(additionalProperties)` two lines above already copies `javaxPackage` into `objsValue` for Java generators, because `applyJavaxPackage()`/`applyJakartaPackage()` write it into `additionalProperties` during `processOpts()`, before `postProcessAllModels()` runs. The new `put` overwrites the same key with the same value, so it cannot change the template context for Java. If the oneOf interface was still rendering `javax`, this line does not fix it — the real cause is likely how the oneOf template consumes the model map entries, not a missing context property. Verify the actual rendering path or remove this no-op.</comment>

<file context>
@@ -603,6 +603,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
                 objsValue.put("classname", cm.classname);
                 objsValue.putAll(additionalProperties);
                 objs.put(cm.name, objsValue);
+                objsValue.put("javaxPackage", additionalProperties.getOrDefault("javaxPackage", "javax"));
             }
 
</file context>

@anupamchaubey
anupamchaubey force-pushed the fix-java-oneof-generated-annotation branch from 08552aa to f004b7f Compare September 7, 2026 18:19
objsValue.put("classname", cm.classname);
objsValue.putAll(additionalProperties);
objs.put(cm.name, objsValue);
objsValue.put("javaxPackage", additionalProperties.getOrDefault("javaxPackage", "javax"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think default codegen should store java specified values (e.g. javaxPackage).

can this be fix in java abstract code gen instead?

@Mattias-Sehlstedt

Mattias-Sehlstedt commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The root cause identified is not correct. The reported issue stemmed from the fact that microprofile itself controlled jakarta with microprofileRestClientVersion, and basically override useJakartaEe. The fix would if anything be to clarify that this is the case for useJakartaEe in the docs (possibly by entirely removing useJakartaEe from microprofile documentation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Java][microprofile] oneOf interface ignores useJakartaEe for @Generated annotation

3 participants