[BUG][JAVA][Spring] 22604 - With NonNull field we can't have an empty constructor#22605
Draft
pkernevez wants to merge 2 commits intoOpenAPITools:masterfrom
Draft
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 373 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java:2904">
P2: Test method name is misleading: `shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable` implies `OPENAPI_NULLABLE` is disabled, but the test sets `OPENAPI_NULLABLE, "true"`. Consider renaming to `shouldGenerateConstructorWithOnlyRequiredParametersWhenOpenapiNullableEnabled` or similar to accurately reflect the test configuration.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| } | ||
|
|
||
| @Test | ||
| public void shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable() throws IOException { |
Contributor
There was a problem hiding this comment.
P2: Test method name is misleading: shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable implies OPENAPI_NULLABLE is disabled, but the test sets OPENAPI_NULLABLE, "true". Consider renaming to shouldGenerateConstructorWithOnlyRequiredParametersWhenOpenapiNullableEnabled or similar to accurately reflect the test configuration.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 2904:
<comment>Test method name is misleading: `shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable` implies `OPENAPI_NULLABLE` is disabled, but the test sets `OPENAPI_NULLABLE, "true"`. Consider renaming to `shouldGenerateConstructorWithOnlyRequiredParametersWhenOpenapiNullableEnabled` or similar to accurately reflect the test configuration.</comment>
<file context>
@@ -2899,6 +2900,30 @@ public void shouldGenerateConstructorWithOnlyRequiredParameters() throws IOExcep
}
+ @Test
+ public void shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable() throws IOException {
+ final Map<String, File> output = generateFromContract(
+ "src/test/resources/3_0/spring/issue_9789.yml",
</file context>
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.
fixes #22604
PR checklist
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)As suggested for Java Spring:
@cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)
This current implementation breaks a lot of existing code, at least by removing the default constructor use by objectmapper. I think people that stay with object mapper will probably not be able to use JSpecify (or at least remove it from generated code).
As mentioned in the issue #22604 we may prefer to introduce a new parameter.
Summary by cubic
Stop generating no-arg constructors for Java Spring models when OPENAPI_NULLABLE is enabled, preventing empty constructors on models with non-nullable fields. Fixes #22604.
Written for commit 2a23228. Summary will update on new commits.