OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] When package is @NullMarked, optional parameters are not @Nullable
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
When useJspecify is enabled, all generated packages are @NullMarked.
However, optional request parameters are not marked with @Nullable, causing verification failures when they are not provided.
openapi-generator version
org.openapitools:openapi-generator-maven-plugin:7.22.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Test
version: v1
paths:
/test:
get:
parameters:
- name: optional
in: query
required: false
schema:
type: string
responses:
200:
description: success
content:
'application/json':
schema:
type: string
Generation Details
<configuration>
<inputSpec>src/main/resources/test.yaml</inputSpec>
<generatorName>java</generatorName>
<library>resttemplate</library>
<apiPackage>com.example</apiPackage>
<invokerPackage>com.example.client</invokerPackage>
<modelPackage>com.example.model</modelPackage>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<ignoreFileOverride>.openapi-generator-ignore</ignoreFileOverride>
<configOptions>
<generateClientAsBean>true</generateClientAsBean>
<openApiNullable>false</openApiNullable>
<useAbstractionForFiles>true</useAbstractionForFiles>
<useJackson3>true</useJackson3>
<useJakartaEe>true</useJakartaEe>
<useJspecify>true</useJspecify>
<useSpringBoot4>true</useSpringBoot4>
</configOptions>
</configuration>
Steps to reproduce
Generate with the above settings.
Observed output
@org.jspecify.annotations.NullMarked
package com.example;
package com.example;
// [...]
/**
*
*
* <p><b>200</b> - success
* @param optional (optional)
* @return String
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public String testGet(String optional) throws RestClientException {
return testGetWithHttpInfo(optional).getBody();
}
Expected output
public String testGet(@Nullable String optional) throws RestClientException {
return testGetWithHttpInfo(optional).getBody();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Java client with the provided OpenAPI declaration and Maven configuration, especially useJspecify=true and openApiNullable=false. Trace the Java generator's handling of optional request parameters and verify that the generated testGet signature marks optional with @Nullable while retaining the existing NullMarked package annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100