[java][jaxrs-spec] - Add support for sealed classes and interfaces with useSealed flag
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:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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 arefinaland implement it. - For discriminator-driven allOf hierarchies, the parent class is sealed and permits its subclasses; subclasses are
final; standalone models becomefinal. - POM uses Java 17 when
useSealedis on; addsjaxrs-spec-sealedsample and registers it in the JDK 17 samples workflow; docs list the option injaxrs-specandjaxrs-cxf-cdi.
- With
-
Bug Fixes
- When
useSealedis enabled withoutuseOneOfInterfaces, drop oneOf-derivedpermitsfrom plain classes to avoid compile errors.
- When