Skip to content

Conversation

@spider-yamet
Copy link

@spider-yamet spider-yamet commented Jan 28, 2026

Description

Fix missing Nullable import in array-type models generated by the Spring codegen. This resolves a compilation error where models using @Nullable annotation in toIndentedString() method were missing the required import.

Fixes #22788

Problem

Array-type models (schemas with type: array without explicit properties) were generated without the org.springframework.lang.Nullable import, causing compilation failure:

Root Cause

The Nullable import was being added in postProcessModelProperty(), 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 Nullable import logic from postProcessModelProperty() to fromModel(), which is called for all models regardless of whether they have properties.

Changes

  • modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
    • Removed Nullable import logic from postProcessModelProperty()
    • Added Nullable import logic to fromModel()
  • modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
    • Added shouldAddNullableImportForArrayTypeModels() test case

PR checklist

  • Added test case to cover the change
  • Documented fix in code comments
  • Verified fix by generating code and confirming successful compilation

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.

  • Bug Fixes
    • Moved import logic to fromModel and extracted helpers, ensuring arrays and operations receive the Nullable import.
    • Added test to verify the import exists for array-type models (AnimalFarm.java) and standard models (Pet.java).

Written for commit 2c985ad. 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.

No issues found across 2 files

@wing328
Copy link
Member

wing328 commented Jan 30, 2026

thanks for the PR

cc @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)

@wing328
Copy link
Member

wing328 commented Jan 30, 2026

thanks for the pr

please follow step 3 to update the samples

@spider-yamet
Copy link
Author

spider-yamet commented Jan 30, 2026

Could you please check again, @wing328? I updated by following steps.

Regards

@spider-yamet
Copy link
Author

@wing328 could you please approve ci pipelines for my update?

Regards

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] Missing @Nullable import for array-type models in 7.19.0

2 participants