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
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
(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
SampleResponsedefinition 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 thecomponents: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
generateSampleApiOpen file
build/generated/error-nullable/src/main/java/com.openapi.bug/SamplecallApi.javaCheck parameter definition for
methodWithNullableParamTo generate the source code WITHOUT @nullable annotation:
Remove the
components:part from the yaml fileyml/error-nullable.yml.Executa Gradle task
generateSampleApiOpen file
build/generated/error-nullable/src/main/java/com.openapi.bug/SamplecallApi.javaCheck parameter definition for
methodWithNullableParamopenapigenerator-nullable-bug.zip