Skip to content

[BUG][SpringBoot4] Method parameter is annotated with org.jspecify.annotations.Nullable but include for annotation is missing in generated code #23757

@UlrichLohrmann

Description

@UlrichLohrmann
Description

A parameter of an API method is annotated with org.jspecify.annotations.Nullable annotation but the annotation is not included in the source file using import. That leads to a compile error.

I stripped down the openAPI yml description to an absolute minimum for reproducing the behavior. While doing this I found out that the @nullable annotation is only generated if the openAPI yml file contains a particular definition in a components: > schemas: part of the yml file.

openapi-generator version

openAPI Gradle plugin 7.22.0

OpenAPI declaration file content or url
openapi: '3.0.3'
info:
  title: Nullable bug demo
  version: '0.0.1'
servers:
  - url: http://localhost:8080/v1

paths:
  /samplecall/{sample-id}:
    put:
      operationId: methodWithNullableParam
      parameters:
        - name: sample-id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: OK

components:
  schemas:
    SampleResponse:
      allOf:
        - type: object

(for YAML code)

Generation Details

The source code for the openAPI yml ist generated using the Gradle task "generateSampleApi" and is then located under build/generated/error-nullable/src/main/java/com.openapi.bug/SamplecallApi.java.

The SampleResponse definition in the yaml file is not referenced by the sample API call. It is enough that it is definied in the yaml to put the @nullable annotation into the source code. If the components: section is removed from the yaml file, no @nullable annotation will be generated.

Steps to reproduce

To generate the source code WITH @nullable annotation:

Ensure the `components' part of the yaml file yml/error-nullable.yml

is the same as shown above.
Executa Gradle task generateSampleApi
Open file build/generated/error-nullable/src/main/java/com.openapi.bug/SamplecallApi.java
Check parameter definition for methodWithNullableParam

To generate the source code WITHOUT @nullable annotation:

Remove the components: part from the yaml file yml/error-nullable.yml.
Executa Gradle task generateSampleApi
Open file build/generated/error-nullable/src/main/java/com.openapi.bug/SamplecallApi.java
Check parameter definition for methodWithNullableParam

openapigenerator-nullable-bug.zip

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