Repository navigation
Conversation
A oneOf interface whose discriminator is an inline enum declared the getter but not the enum, while each implementor declared its own copy. The interface did not compile. The interface now declares the enum and the implementors reuse it. Fixes OpenAPITools#25398
There was a problem hiding this comment.
2 issues found across 15 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/Java/oneof_interface.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/Java/oneof_interface.mustache:6">
P2: Property-level oneOf interfaces still omit inline discriminator enums because this template only renders enums from `vars`, while `addOneOfInterfaceModel` creates those synthetic interfaces without populating `vars`. Populate the synthetic interface's discriminator property or render the enum from discriminator metadata, then cover this form with a regression test.</violation>
<violation number="2" location="modules/openapi-generator/src/main/resources/Java/oneof_interface.mustache:9">
P2: The discriminator enum rendered here uses `@JsonCreator`, but the oneOf interface model may not import `com.fasterxml.jackson.annotation.JsonCreator`. Confirm the generated interface compiles with jackson, or add the import explicitly as the JAX-RS template does.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| {{#vars}} | ||
| {{#isEnum}} | ||
| {{#isDiscriminator}} | ||
| {{>modelInnerEnum}} |
There was a problem hiding this comment.
P2: The discriminator enum rendered here uses @JsonCreator, but the oneOf interface model may not import com.fasterxml.jackson.annotation.JsonCreator. Confirm the generated interface compiles with jackson, or add the import explicitly as the JAX-RS template does.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/Java/oneof_interface.mustache, line 9:
<comment>The discriminator enum rendered here uses `@JsonCreator`, but the oneOf interface model may not import `com.fasterxml.jackson.annotation.JsonCreator`. Confirm the generated interface compiles with jackson, or add the import explicitly as the JAX-RS template does.</comment>
<file context>
@@ -3,6 +3,13 @@
+ {{#vars}}
+ {{#isEnum}}
+ {{#isDiscriminator}}
+{{>modelInnerEnum}}
+ {{/isDiscriminator}}
+ {{/isEnum}}
</file context>
| {{{.}}} | ||
| {{/vendorExtensions.x-class-extra-annotation}} | ||
| public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}{{>permits}}{ | ||
| {{#vars}} |
There was a problem hiding this comment.
P2: Property-level oneOf interfaces still omit inline discriminator enums because this template only renders enums from vars, while addOneOfInterfaceModel creates those synthetic interfaces without populating vars. Populate the synthetic interface's discriminator property or render the enum from discriminator metadata, then cover this form with a regression test.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/Java/oneof_interface.mustache, line 6:
<comment>Property-level oneOf interfaces still omit inline discriminator enums because this template only renders enums from `vars`, while `addOneOfInterfaceModel` creates those synthetic interfaces without populating `vars`. Populate the synthetic interface's discriminator property or render the enum from discriminator metadata, then cover this form with a regression test.</comment>
<file context>
@@ -3,6 +3,13 @@
{{{.}}}
{{/vendorExtensions.x-class-extra-annotation}}
public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}{{>permits}}{
+ {{#vars}}
+ {{#isEnum}}
+ {{#isDiscriminator}}
</file context>
|
@cpruijsen Thanks for this PR. As I'm only interested at a fix for java and Spring, your PR is probably simpler. You update AbstractJavaCodegen so the implementation should be valid for all java generators. |
|
Thanks! java/oneof_interface already includes |
…f discriminator enum
Fixes #25398
A oneOf interface whose discriminator is an inline enum declared
PetTypeEnum getPetType()without declaringPetTypeEnum. Each implementor declared a separate nested enum. The interface did not compile, and the implementor enums could not satisfy its getter.The interface now declares the inline enum, and implementors reuse the inherited nested type.
Changes:
AbstractJavaCodegenkeeps interface-owned inline enums and clearsisEnumon interface properties collected from implementors. It also clears the flag on discriminator copies pushed into implementors. The [REQ] [Java] Allow excluding discriminator property from generated models #24769 implementor-owned case is unchanged. Groovy is excluded because it does not render Java oneOf interfaces.isEnumandisDiscriminatorare set. JAX-RS also renders the required Jackson, JSON-B, or XML imports.isInnerEnum, so copied properties retain their enum type and values afterisEnumis cleared.bugs/issue_25398.yaml. No new vendor extension is added.Implementation choice: shared Java post-processing covers every Java interface template. A Spring-only pass would be smaller but would leave the same defect in Java, JAX-RS Spec, and Micronaut. Repairing the pre-existing class-based oneOf hierarchy in native,
okhttp-gson, Jersey, and Helidon is outside this change.Checks:
checkstyle:check:BUILD SUCCESS.javac. JAX-RS also type-checks with JSON-B and XML.PetTypeEnumis missing.Dog.mdretain the enum type and values.PR checklist
Read the contribution guidelines.
Run the following to build the project and update samples:
(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.
I ran
./bin/generate-samples.sh ./bin/configs/*.yamland./bin/utils/export_docs_generators.shwith this change. Neither changed a committed file, so the PR has no sample changes.If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @KannaKim (Java)
@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente (Java Spring)