DRAFT: Pr1 jaxrs useoneofinterfaces#24174
Draft
Ignacio-Vidal wants to merge 2 commits into
Draft
Conversation
getDiscriminatorPropertyType resolved the discriminator property's type only from the oneOf/anyOf schema's own properties, defaulting to "string" when the property was not declared there. For a pure oneOf interface whose discriminator property lives on a shared base that the children inherit via allOf, this produced a String getter type that clashed with the enum the subtypes actually expose. Add the resolution to DiscriminatorUtils (alongside the existing getDiscriminatorPropertyType / getDiscriminatorSchema): getDiscriminatorPropertyType now falls back to the mapped child schemas, chasing the discriminator property through each child's allOf members (getDiscriminatorPropertyTypeFromChildren / getDiscriminatorSchemaDeep). The allOf descent tracks visited schemas to guard against a cyclic allOf composition recursing infinitely. The fallback only fires when the own-properties lookup is empty, so the type now resolves to the enum ref (e.g. PetType) when a child declares the discriminator property as a $ref, and otherwise still falls back to "string". DefaultCodegen.getDiscriminatorPropertyType becomes a thin binding that maps the resolved schema ref name to a generator-specific model name and applies the "string" default, as those depend on this codegen's instance state. The first resolution branch is unchanged, so existing specs are unaffected: regenerating the full sample suite produces no diffs.
The jaxrs-spec generator had no rendering for the useOneOfInterfaces feature: a oneOf schema was always emitted as a pojo, even when the feature transformed it into an interface model. This adds the missing interface template so that, with useOneOfInterfaces=true, a oneOf schema is generated as a Java interface and the concrete subtypes implement it. - model.mustache routes x-is-one-of-interface models to a new oneof_interface template; all other models still render as pojos (default behavior unchanged). - oneof_interface.mustache emits a plain interface, carrying the discriminator getter (whose type now resolves to the shared enum, e.g. PetType) plus the generated/typeInfo/deduction annotations. - Adds the oneof_interface fixture, a JavaJAXRSSpecServerCodegenTest, and a jaxrs-spec-oneof-interface sample (registered in the JAX-RS samples workflow). The feature stays opt-in; default jaxrs-spec output is unchanged.
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.
Summary by cubic
Fixes discriminator type resolution for oneOf/anyOf interfaces and adds
useOneOfInterfacessupport tojaxrs-spec. Interfaces now use the correct enum type instead of String; feature is opt-in and default output is unchanged.Bug Fixes
DefaultCodegento use the new resolution with a safe "string" fallback when no typed schema is found.New Features
jaxrs-spec: generate Java interfaces for oneOf whenuseOneOfInterfaces=truevia a newoneof_interface.mustachetemplate.samples/server/petstore/jaxrs-spec-oneof-interface, tests, and CI workflow entry.Written for commit 280a2f6. Summary will update on new commits.