[BUG][kotlin-spring] missing JsonInclude import for optional+nullable-only models when using jsonNullable#24368
Conversation
…dels to prevent compilation errors
…n.annotation.JsonInclude
There was a problem hiding this comment.
1 issue found across 12 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="samples/server/petstore/springboot-sort-validation/src/main/java/org/openapitools/model/OptionalNullableOnlyModel.java">
<violation number="1" location="samples/server/petstore/springboot-sort-validation/src/main/java/org/openapitools/model/OptionalNullableOnlyModel.java:10">
P3: Duplicate `JsonNullable` import in the generated Java model. The import `org.openapitools.jackson.nullable.JsonNullable` appears twice (lines 12 and 19). While Java permits duplicate imports without a compilation error, this dead import is unnecessary and suggests the generator's import-dedup logic can produce a double entry when both the main code path and the `JsonInclude`-fix path independently add the same import. Removing the second occurrence keeps the generated code clean.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import java.util.Arrays; | ||
| import java.util.UUID; | ||
| import org.openapitools.jackson.nullable.JsonNullable; |
There was a problem hiding this comment.
P3: Duplicate JsonNullable import in the generated Java model. The import org.openapitools.jackson.nullable.JsonNullable appears twice (lines 12 and 19). While Java permits duplicate imports without a compilation error, this dead import is unnecessary and suggests the generator's import-dedup logic can produce a double entry when both the main code path and the JsonInclude-fix path independently add the same import. Removing the second occurrence keeps the generated code clean.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/springboot-sort-validation/src/main/java/org/openapitools/model/OptionalNullableOnlyModel.java, line 10:
<comment>Duplicate `JsonNullable` import in the generated Java model. The import `org.openapitools.jackson.nullable.JsonNullable` appears twice (lines 12 and 19). While Java permits duplicate imports without a compilation error, this dead import is unnecessary and suggests the generator's import-dedup logic can produce a double entry when both the main code path and the `JsonInclude`-fix path independently add the same import. Removing the second occurrence keeps the generated code clean.</comment>
<file context>
@@ -0,0 +1,99 @@
+import com.fasterxml.jackson.annotation.JsonCreator;
+import java.util.Arrays;
+import java.util.UUID;
+import org.openapitools.jackson.nullable.JsonNullable;
+import org.springframework.lang.Nullable;
+import java.util.NoSuchElementException;
</file context>
There was a problem hiding this comment.
This is existing issue. I will eventually fix it, but I want to focus on the core issue here
There was a problem hiding this comment.
for duplicate import, i think we can create a lambda to remove duplicated lines in a text block. not the best approach but i think it should work.
There was a problem hiding this comment.
I can fix the root cause in this case. It is just that this very PR fixes very similar oversight where the import was not added at all. I am worried that I might introduce another regression. But I will take a stab at it.
There was a problem hiding this comment.
I fixed the issue with the duplicate JsonNullable import. It was removed from A LOT of samples.
There was a problem hiding this comment.
So in general @wing328 , I think this can be merged whenever you feel like it.
There was a problem hiding this comment.
No issues found across 1560 files
Note: This PR contains a large number of files. cubic only reviews up to 200 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
Re-trigger cubic
fixes #24365
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
Fixes missing
com.fasterxml.jackson.annotation.JsonIncludeimport in Kotlin Spring models whose only field is optional + nullable whenjsonNullableis enabled, preventing compile errors from@field:JsonInclude(NON_ABSENT). Also ensuresorg.openapitools.jackson.nullable.JsonNullableis imported only when nullable fields are present.JsonIncludeto model imports whenopenApiNullable=trueand a property is optional + nullable (including optional+nullable-only models).JsonNullableimport whenever a property is nullable and remove the unconditional import fromJavaSpring/model.mustache.JsonNullableimports.Written for commit ee2e636. Summary will update on new commits.