Skip to content

[BUG][JAVA] When package is @NullMarked, optional parameters are not @Nullable #23656

@OrangeDog

Description

@OrangeDog

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();
    }

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