Skip to content

DRAFT: [java][jaxrs-spec][quarkus] - Part 2 - useSealed interfaces#24189

Draft
Ignacio-Vidal wants to merge 2 commits into
OpenAPITools:masterfrom
Ignacio-Vidal:pr2-jaxrs-usesealed
Draft

DRAFT: [java][jaxrs-spec][quarkus] - Part 2 - useSealed interfaces#24189
Ignacio-Vidal wants to merge 2 commits into
OpenAPITools:masterfrom
Ignacio-Vidal:pr2-jaxrs-usesealed

Conversation

@Ignacio-Vidal

@Ignacio-Vidal Ignacio-Vidal commented Jul 2, 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

Adds support for generating oneOf schemas as Java interfaces in jaxrs-spec (optionally sealed), and fixes discriminator mapping so subtypes get correct @JsonTypeName and interface getters use the enum type.

  • New Features

    • useOneOfInterfaces=true: oneOf schemas render as interfaces via oneof_interface.mustache; subtypes implement the interface and carry Jackson type info.
    • useSealed=true (with useOneOfInterfaces): emits sealed interfaces with permits; subtypes become final and implement the interface; pom.mustache sets Java 17 when enabled.
    • New templates: oneof_interface.mustache, sealed.mustache, permits.mustache, additionalOneOfTypeAnnotations.mustache; workflows build new samples: jaxrs-spec-oneof-interface (JAX-RS), jaxrs-spec-sealed (JDK17).
  • Bug Fixes

    • Ensures x-discriminator-value for subtypes is resolved from the parent or from the implemented oneOf interface, producing the correct @JsonTypeName (e.g., CAT/DOG).
    • Interface discriminator getter now uses the resolved enum type (e.g., PetType) instead of defaulting to String.

Written for commit 05ce164. Summary will update on new commits.

Review in cubic

@Ignacio-Vidal Ignacio-Vidal changed the title DRAFT: [java][jaxrs-spec][quarkus] - useSealed interfaces DRAFT: [java][jaxrs-spec][quarkus] - Part 2 - useSealed interfaces Jul 2, 2026
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.
Adds a useSealed option to the jaxrs-spec generator. When useSealed=true (on top
of useOneOfInterfaces=true), the generated oneOf interface is sealed and permits
its subtypes, which become final classes implementing the interface.

- JavaJAXRSSpecServerCodegen: useSealed option (constant/field/CliOption/processOpts).
- sealed.mustache / permits.mustache emit the sealed/permits/final modifiers,
  gated on useSealed; oneof_interface.mustache and pojo.mustache reference them so
  the modifiers appear on both the interface and the pojos.
- pom.mustache bumps java.version to 17 when useSealed (sealed types need JDK 17+);
  the default stays 1.8.
- Adds testOneOfSealedInterfaceGeneration and a jaxrs-spec-sealed sample
  (registered in the JDK17 samples workflow).

The feature stays opt-in; default jaxrs-spec output is unchanged.
@Ignacio-Vidal Ignacio-Vidal force-pushed the pr2-jaxrs-usesealed branch from 98907a7 to 05ce164 Compare July 2, 2026 23:35
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.

1 participant