Skip to content

[BUG][JavaSpring] Missing nullable annotations for Spring controller definitions and optional parameters #21200

Open
@ondrej-simon

Description

@ondrej-simon

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

When adopting Kotlin, we still generate Spring server models and controller interfaces to Java, because Kotlin generator does not fully support advanced constructs such as oneOf. We then implement generated Spring interfaces in Kotlin (and use generated Java models also in Kotlin).

We found a limitation where Nullable annotations:

  • are generated for member variables, but not for getters and setters,
  • are not generated at all for Query/Cookie/Header params and optional request bodies,

which in turn incorrectly marks even optional attributes as always present and increases risk of NPE.

Release 7.13.0 started adding Nullable annotations to Java clients (e.g. WebClient, RestClient) for input parameters, but these are still missing when generating Spring Boot stubs.

openapi-generator version

7.14.0-SNAPSHOT

OpenAPI declaration file content or url

Any OpenApi Specification where:

  • header/query/cookie param is optional without default value,
  • request body is marked as required=false,
  • schema property not marked as required.
Generation Details
  • Switch to master.
  • Generate Spring Boot stubs.
  • Nullable annotations are missing for optional headers, query params, cookies and request bodies.
Steps to reproduce

See Generation Details above.

Suggest a fix

I will open PR fixing this issue.

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