Skip to content

Conversation

@pkernevez
Copy link
Contributor

@pkernevez pkernevez commented Dec 30, 2025

fixes #22604

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and - [ ] File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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.

  • Bug Fixes
    • x-java-no-args-constructor now respects OPENAPI_NULLABLE and skips emitting a no-arg constructor when OPENAPI_NULLABLE=true.
    • Added tests for both OPENAPI_NULLABLE=true/false paths.
    • Regenerated Spring samples to remove invalid no-arg constructors.

Written for commit 2a23228. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, &quot;true&quot;`. 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 {
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, &quot;true&quot;`. 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&lt;String, File&gt; output = generateFromContract(
+                &quot;src/test/resources/3_0/spring/issue_9789.yml&quot;,
</file context>
Fix with Cubic

@pkernevez pkernevez marked this pull request as draft December 30, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][JAVA][Spring] With NonNull field we can't have an empty constructor

1 participant