Skip to content

[java][jaxrs-spec] - Add support for sealed classes and interfaces with useSealed flag #24189

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
Ignacio-Vidal:pr2-jaxrs-usesealed
Jul 10, 2026
Merged

[java][jaxrs-spec] - Add support for sealed classes and interfaces with useSealed flag #24189
wing328 merged 1 commit into
OpenAPITools:masterfrom
Ignacio-Vidal:pr2-jaxrs-usesealed

Conversation

@Ignacio-Vidal

@Ignacio-Vidal Ignacio-Vidal commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in useSealed option to the jaxrs-spec generator (follows #24174). When enabled, generated models form closed (sealed) hierarchies using Java 17 sealed types, mirroring the existing useSealed semantics of the Spring generator. The generated pom.xml targets Java 17 when the option is on (default stays 1.8), and the default output without the flag is unchanged (guarded by a regression test).

Scenarios covered

Spec shape Flags Generated code
oneOf schema + discriminator useOneOfInterfaces + useSealed public sealed interface PetRequest permits CatRequest, DogRequest — subtypes are final classes implementing it
allOf hierarchy (parent holds the discriminator) useSealed only public sealed class Pet permits Cat, Dog — subclasses are final and extends Pet
Multi-level hierarchy (middle tier with its own discriminator) useSealed only public sealed class Cat extends Pet permits PersianCat — sealed and permitted at the same time; leaves are final
oneOf schema + discriminator useSealed without useOneOfInterfaces Without useOneOfInterfaces a oneOf schema is generated as a regular class with the members' properties merged in (unchanged from master). Its members are unrelated classes — they do not extend it — so sealing it over them would not compile. The generator therefore emits it as a plain final class: internally, postProcessAllModels removes the oneOf-derived permits entries that core populates unconditionally
Standalone model (no subtypes) useSealed public final class Toy
Any spec flag off (default) Output unchanged — no sealed/final/permits, pom stays at Java 1.8

Each scenario is pinned by a test in JavaJAXRSSpecServerCodegenTest, and a jaxrs-spec-sealed sample (registered in the JDK17 samples workflow) compiles the sealed output in CI. A full 771-config sample + docs regeneration produces zero diffs outside this PR's own sample and doc rows.


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 useSealed to jaxrs-spec to generate sealed oneOf interfaces and sealed allOf parent classes with final subtypes. Also switches generated POMs to Java 17 when enabled, adds a jaxrs-spec-sealed sample to the JDK 17 workflow, and updates docs.

  • New Features

    • With useOneOfInterfaces=true, the oneOf interface is sealed and permits its subtypes; subtypes are final and implement it.
    • For discriminator-driven allOf hierarchies, the parent class is sealed and permits its subclasses; subclasses are final; standalone models become final.
    • POM uses Java 17 when useSealed is on; adds jaxrs-spec-sealed sample and registers it in the JDK 17 samples workflow; docs list the option in jaxrs-spec and jaxrs-cxf-cdi.
  • Bug Fixes

    • When useSealed is enabled without useOneOfInterfaces, drop oneOf-derived permits from plain classes to avoid compile errors.

Written for commit 649d1b7. 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
@Ignacio-Vidal Ignacio-Vidal force-pushed the pr2-jaxrs-usesealed branch 2 times, most recently from 05ce164 to 150c5a2 Compare July 9, 2026 17:23
@Ignacio-Vidal Ignacio-Vidal marked this pull request as ready for review July 9, 2026 17:48

@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.

All reported issues were addressed across 25 files

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

Re-trigger cubic

@Ignacio-Vidal Ignacio-Vidal force-pushed the pr2-jaxrs-usesealed branch 2 times, most recently from 323c20b to 649d1b7 Compare July 9, 2026 18:49
@Ignacio-Vidal Ignacio-Vidal changed the title DRAFT: [java][jaxrs-spec][quarkus] - Part 2 - useSealed interfaces [java][jaxrs-spec][quarkus] Add support for sealed classes and interfaces with useSealed flag Jul 9, 2026
Adds a useSealed option to the jaxrs-spec generator.

- With useOneOfInterfaces=true, the generated oneOf interface is sealed and
  permits its subtypes, which become final classes implementing the interface.
- On its own, an allOf class hierarchy driven by a parent discriminator becomes
  a sealed parent class permitting its subclasses, which extend it and become
  final; standalone models become final.
- JavaJAXRSSpecServerCodegen: useSealed option (constant/field/CliOption/processOpts);
  postProcessAllModels drops oneOf-derived permits from models rendered as plain
  classes (their oneOf members do not extend them, so a permits clause would not
  compile).
- sealed.mustache / permits.mustache emit the sealed/permits/final modifiers,
  gated on useSealed; oneof_interface.mustache and pojo.mustache reference them.
- pom.mustache bumps java.version to 17 when useSealed (sealed types need JDK 17+);
  the default stays 1.8.
- Tests: sealed oneOf interface, sealed allOf class hierarchy, useSealed without
  useOneOfInterfaces (compilable output), defaults unchanged without useSealed.
- Adds 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 649d1b7 to 0f9d879 Compare July 9, 2026 19:52
@Ignacio-Vidal

Copy link
Copy Markdown
Contributor Author

@wing328 - Any chance you could review a follow up of #24174

@Ignacio-Vidal Ignacio-Vidal changed the title [java][jaxrs-spec][quarkus] Add support for sealed classes and interfaces with useSealed flag [java][jaxrs-spec] - Add support for sealed classes and interfaces with useSealed flag Jul 9, 2026
@wing328 wing328 merged commit fa7ef56 into OpenAPITools:master Jul 10, 2026
57 checks passed
@wing328 wing328 added this to the 7.24.0 milestone Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants