Skip to content

DRAFT: Pr1 jaxrs useoneofinterfaces#24174

Draft
Ignacio-Vidal wants to merge 2 commits into
OpenAPITools:masterfrom
Ignacio-Vidal:pr1-jaxrs-useoneofinterfaces
Draft

DRAFT: Pr1 jaxrs useoneofinterfaces#24174
Ignacio-Vidal wants to merge 2 commits into
OpenAPITools:masterfrom
Ignacio-Vidal:pr1-jaxrs-useoneofinterfaces

Conversation

@Ignacio-Vidal

@Ignacio-Vidal Ignacio-Vidal commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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.

Summary by cubic

Fixes discriminator type resolution for oneOf/anyOf interfaces and adds useOneOfInterfaces support to jaxrs-spec. Interfaces now use the correct enum type instead of String; feature is opt-in and default output is unchanged.

  • Bug Fixes

    • Resolve discriminator property type from child schemas (oneOf/anyOf), following allOf into shared bases to get the enum ref instead of falling back to String.
    • Prevent infinite recursion by guarding against cyclic allOf compositions.
    • Update DefaultCodegen to use the new resolution with a safe "string" fallback when no typed schema is found.
  • New Features

    • jaxrs-spec: generate Java interfaces for oneOf when useOneOfInterfaces=true via a new oneof_interface.mustache template.
    • Interface includes Jackson type info and declares the discriminator getter with the resolved type; concrete subtypes implement it.
    • Add sample samples/server/petstore/jaxrs-spec-oneof-interface, tests, and CI workflow entry.

Written for commit 280a2f6. Summary will update on new commits.

Review in cubic

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.
@Ignacio-Vidal Ignacio-Vidal changed the title Pr1 jaxrs useoneofinterfaces Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant