Skip to content

[BUG] [Spring] Nullable annotation not imported in Spring-Boot controllers #23581

@jpfinne

Description

@jpfinne

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

Compilation error for generated spring-boot generated rest controller.
@Nullable annotation is set for NativeWebRequest. The annotation is not imported in all cases. For example when the operations have only required arguments.

openapi-generator version

7.22.0-SNAPSHOT

OpenAPI declaration file content or url
Generation Details

java -jar openapi-generator-cli.jar generate -g spring --library spring-boot -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/output

Steps to reproduce

The generated /tmp/output/src/main/java/org/openapitools/api/UserApiController.java
contains a @Nullable annotation, but no import.

It gives a compilation error

Related issues/PRs

Regression due to #23256

Suggest a fix

Quick fix: remove the annotation from apiController.mustache
Mid term fix:

correclty add @Nullable annotation in all the java and spring generators. The goal is is to avoid false alarms when using JSpecify. Ensure that @Nullable annotations are correctly imported

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