[java][jaxrs-spec] - Add support for sealed classes and interfaces with useSealed flag #24189
Merged
Merged
Conversation
05ce164 to
150c5a2
Compare
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 25 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
323c20b to
649d1b7
Compare
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.
649d1b7 to
0f9d879
Compare
Contributor
Author
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.
Summary
Adds an opt-in
useSealedoption to the jaxrs-spec generator (follows #24174). When enabled, generated models form closed (sealed) hierarchies using Java 17 sealed types, mirroring the existinguseSealedsemantics of the Spring generator. The generatedpom.xmltargets 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
useOneOfInterfaces+useSealedpublic sealed interface PetRequest permits CatRequest, DogRequest— subtypes arefinalclasses implementing ituseSealedonlypublic sealed class Pet permits Cat, Dog— subclasses arefinalandextends PetuseSealedonlypublic sealed class Cat extends Pet permits PersianCat— sealed and permitted at the same time; leaves arefinaluseSealedwithoutuseOneOfInterfacesuseOneOfInterfacesa 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 plainfinalclass: internally,postProcessAllModelsremoves the oneOf-derivedpermitsentries that core populates unconditionallyuseSealedpublic final class Toysealed/final/permits, pom stays at Java 1.8Each scenario is pinned by a test in
JavaJAXRSSpecServerCodegenTest, and ajaxrs-spec-sealedsample (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
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
Adds
useSealedtojaxrs-specto generate sealed oneOf interfaces and sealed allOf parent classes with final subtypes. Also switches generated POMs to Java 17 when enabled, adds ajaxrs-spec-sealedsample to the JDK 17 workflow, and updates docs.New Features
useOneOfInterfaces=true, the oneOf interface is sealed and permits its subtypes; subtypes arefinaland implement it.final; standalone models becomefinal.useSealedis on; addsjaxrs-spec-sealedsample and registers it in the JDK 17 samples workflow; docs list the option injaxrs-specandjaxrs-cxf-cdi.Bug Fixes
useSealedis enabled withoutuseOneOfInterfaces, drop oneOf-derivedpermitsfrom plain classes to avoid compile errors.Written for commit 649d1b7. Summary will update on new commits.