-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
DRAFT: [java][jaxrs-spec][quarkus] - Part 2 - useSealed interfaces #24189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ignacio-Vidal
wants to merge
1
commit into
OpenAPITools:master
Choose a base branch
from
Ignacio-Vidal:pr2-jaxrs-usesealed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| generatorName: jaxrs-spec | ||
| outputDir: samples/server/petstore/jaxrs-spec-sealed | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/oneof_interface.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/spec | ||
| additionalProperties: | ||
| artifactId: jaxrs-spec-sealed-petstore-server | ||
| useOneOfInterfaces: "true" | ||
| useSealed: "true" | ||
| serializableModel: "true" | ||
| hideGenerationTimestamp: "true" |
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
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
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
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
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/main/resources/JavaJaxRS/spec/permits.mustache
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#useSealed}}{{#permits}}{{#-first}}permits {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}} {{/-last}}{{/permits}}{{/useSealed}} |
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
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
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/main/resources/JavaJaxRS/spec/sealed.mustache
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#useSealed}}{{#permits.0}}sealed {{/permits.0}}{{^permits.0}}{{^vendorExtensions.x-is-one-of-interface}}final {{/vendorExtensions.x-is-one-of-interface}}{{/permits.0}}{{/useSealed}} |
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
59 changes: 59 additions & 0 deletions
59
modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/sealed_hierarchy.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: sealed class hierarchy | ||
| description: > | ||
| An allOf class hierarchy driven by a parent discriminator. Under useSealed the | ||
| parent class is sealed and permits its subclasses, which extend it and become final. | ||
| version: 1.0.0 | ||
| paths: | ||
| /pets: | ||
| post: | ||
| operationId: createPet | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Pet' | ||
| responses: | ||
| '201': | ||
| description: created | ||
| components: | ||
| schemas: | ||
| Pet: | ||
| type: object | ||
| required: | ||
| - petType | ||
| - name | ||
| properties: | ||
| petType: | ||
| type: string | ||
| name: | ||
| type: string | ||
| discriminator: | ||
| propertyName: petType | ||
| mapping: | ||
| CAT: '#/components/schemas/Cat' | ||
| DOG: '#/components/schemas/Dog' | ||
|
|
||
| Cat: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: object | ||
| properties: | ||
| indoor: | ||
| type: boolean | ||
|
|
||
| Dog: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: object | ||
| properties: | ||
| trained: | ||
| type: boolean | ||
|
|
||
| Toy: | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string |
23 changes: 23 additions & 0 deletions
23
samples/server/petstore/jaxrs-spec-sealed/.openapi-generator-ignore
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # OpenAPI Generator Ignore | ||
| # Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
|
||
| # Use this file to prevent files from being overwritten by the generator. | ||
| # The patterns follow closely to .gitignore or .dockerignore. | ||
|
|
||
| # As an example, the C# client generator defines ApiClient.cs. | ||
| # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
| #ApiClient.cs | ||
|
|
||
| # You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
| #foo/*/qux | ||
| # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
|
||
| # You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
| #foo/**/qux | ||
| # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
|
||
| # You can also negate patterns with an exclamation (!). | ||
| # For example, you can ignore all files in a docs folder with the file extension .md: | ||
| #docs/*.md | ||
| # Then explicitly reverse the ignore rule for a single file: | ||
| #!docs/README.md |
11 changes: 11 additions & 0 deletions
11
samples/server/petstore/jaxrs-spec-sealed/.openapi-generator/FILES
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| README.md | ||
| pom.xml | ||
| src/gen/java/org/openapitools/api/PetsApi.java | ||
| src/gen/java/org/openapitools/api/RestApplication.java | ||
| src/gen/java/org/openapitools/api/RestResourceRoot.java | ||
| src/gen/java/org/openapitools/model/CatRequest.java | ||
| src/gen/java/org/openapitools/model/DogRequest.java | ||
| src/gen/java/org/openapitools/model/PetBase.java | ||
| src/gen/java/org/openapitools/model/PetRequest.java | ||
| src/gen/java/org/openapitools/model/PetType.java | ||
| src/main/openapi/openapi.yaml |
1 change: 1 addition & 0 deletions
1
samples/server/petstore/jaxrs-spec-sealed/.openapi-generator/VERSION
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 7.24.0-SNAPSHOT |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Missing validation that
useSealed=truerequiresuseOneOfInterfaces=true. The PR description and design documentation both state thatuseSealedrequiresuseOneOfInterfaces, but the code only wires up the option value without checking this prerequisite. WhenuseSealed=trueis set withoutuseOneOfInterfaces=true, thesealed.mustachetemplate still applies thefinalkeyword to every POJO class (since the template outputsfinalfor non-sealed, non-oneof-interface classes whenuseSealedis true), which silently changes the generated code and could break existing consumers that rely on subclassing generated model classes. The codebase already has an established validation pattern for cross-option dependencies — for example,useJakartaSecurityAnnotationsvalidates thatuseJakartaEe=trueis also set with a clearIllegalArgumentException. The same pattern should be applied here.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid catch that
useSealed=truewithoutuseOneOfInterfaceswas an untested combination, but it is resolved by making the combination first-class rather than rejecting it, for two reasons:useSealedis useful on its own: an allOf hierarchy driven by a parent discriminator generatespublic sealed class Pet permits Cat, Dogwithfinalsubclasses that extend it — no oneOf interfaces involved. RequiringuseOneOfInterfaceswould forbid that use case.useSealedsemantics in the Spring generator, which has no such prerequisite (Spring renders oneOf containers as interfaces natively, so it never hits the broken case below).There WAS a real bug in this combination: core adds oneOf members to
CodegenModel.permitsunconditionally, so a oneOf container rendered as a plain class (nouseOneOfInterfaces) producedpublic sealed class PetRequest permits CatRequest, DogRequestwhile neither subtype extends it — uncompilable. Fixed inpostProcessAllModels: oneOf-derived permits are dropped from models not rendered as oneOf interfaces, so the container degrades to afinalclass like any other model without subclasses.The
final-on-every-pojo behavior whenuseSealed=trueis intentional and identical to the Spring generator'suseSealed(the templates are the same); it only affects users who opt into the flag.New tests cover all of this:
testSealedClassHierarchyGeneration,testUseSealedWithoutOneOfInterfaces, andtestWithoutUseSealedOutputIsUnchanged(defaults regression, pom stays 1.8).