[Java][jaxrs-spec] Fix JsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema Name#23509
Open
thiswasdumb wants to merge 2 commits intoOpenAPITools:masterfrom
Open
Conversation
…the key from the oneOf pattern instead of the schema name
Contributor
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java:1246">
P2: The new test points to `pestore.yaml`, but the only file in this directory is `petstore.yaml`. This will cause the test to fail when the OpenAPIParser cannot load the spec. Use the correct filename.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...erator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java
Outdated
Show resolved
Hide resolved
…en/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java Putting the proper petstore file as it was incorrectly committed before, many apologies! Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Author
|
If it is okay, could I possibly get some reviews from the tech committee? I saw @chameleon82 is connected to JAX-RS RestEasy, @hiveship is connected to JAX-RS CXF, and @Zomzog is connected to Java generally. I am sorry if I tagged and you aren't too closely related, but I would greatly appreciate any reviews! Thank you so much :) |
JsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema NameJsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema Name
JsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema NameJsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema Name
JsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema NameJsonTypeName Generation With allOf and oneOf Combination to Match Key Instead of Schema Name
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.
Description
When using
allOfandoneOfto generate properly nested classes that extend a parent, the generated@JsonTypeNamefollows the name of the child schemas as opposed to the discriminator used. This serves problematic when sending requests to a server and receiving responses following the same format, because the openapi contract will expect the key but will attempt to deserialize the schema name.The fix is to set it so it prioritizes a discriminator value being set, but will take the key and finally the schema name if no key is found.
This MR will fix #10822 and will fix #17343
Changes
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.javaholds the logic for determining what should be in the generatedJsonTypeNamefieldmodules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustacheis responsible to look for the x-discriminator-value but also not automatically set it as the schema namemodules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.javaholds testing to verify this works as expectedmodules/openapi-generator/src/test/resources/3_0/jaxrs/petstore.yamlincludes generated classes using theoneOfandallOflogic to ensure the flow works as expectedHow to Reproduce
Add the current changes from petstore.yaml and generate that file and view the generated classes. You will find that
CatRequest.javaandDogRequest.javaboth extendPetRequest.javaproperly, but their@JsonTypeNamefields containCatRequestandDogRequestinstead ofCATandDOG.Adding the logic you will find the change to be the expected keys instead.
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)