Skip to content

[BUG][SPRING] Missing org.springframework.lang.Nullable import in custom generators extending SpringCodegen #21070

@jorgerod

Description

@jorgerod

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

After upgrading to OpenAPI Generator 7.11.0, a regression has been introduced that affects custom generators extending SpringCodegen (info about custom generators).

When generating models, the import for org.springframework.lang.Nullable is not being added, even though the annotation is used in the generated code. This results in compilation errors out of the box.

This is a breaking change introduced in a minor version, which violates semantic versioning expectations. Custom generators that previously worked are now broken after upgrading, without any clear migration notes or warnings.

openapi-generator version

7.11.0

✅ Expected Behavior

Generated code should include the necessary import for org.springframework.lang.Nullable and compile without issues.

❌ Actual Behavior

The generated code uses @Nullable, but the import is missing, leading to compilation errors.

Steps to reproduce
  1. Create a custom generator that extends org.openapitools.codegen.languages.SpringCodegen.
  2. Generate model classes with nullable properties.
  3. Try to compile the generated output.
Workaround

As a temporary workaround, add this override method in your custom generator:

  @Override
  public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
    super.postProcessModelProperty(model, property);
    model.imports.add("Nullable");
  }
Related issues/PRs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions