fix(spring): Add Nullable import for array-type models (#22788) #22844
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
Fix missing
Nullableimport in array-type models generated by the Spring codegen. This resolves a compilation error where models using@Nullableannotation intoIndentedString()method were missing the required import.Fixes #22788
Problem
Array-type models (schemas with
type: arraywithout explicit properties) were generated without theorg.springframework.lang.Nullableimport, causing compilation failure:Root Cause
The
Nullableimport was being added inpostProcessModelProperty(), but this method is only called for models with properties. Array-type models have no properties, so the hook was never invoked.Solution
Moved the
Nullableimport logic frompostProcessModelProperty()tofromModel(), which is called for all models regardless of whether they have properties.Changes
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.javaNullableimport logic frompostProcessModelProperty()Nullableimport logic tofromModel()modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.javashouldAddNullableImportForArrayTypeModels()test casePR checklist
Summary by cubic
Fixes missing org.springframework.lang.Nullable import in Spring-generated array-type models, preventing compilation errors when @nullable is used in toIndentedString(). The import is now added for all models.
Written for commit 2c985ad. Summary will update on new commits.