Skip to content

[BUG] [java] [spring] type: [string, "null"] isn't generating JsonNullable properties #20827

Open

Description

@jmuellerdeposco

Bug Report Checklist

Description

When using allOf and 2 references, the generated classes do not use JsonNullable. However, when the properties are defined inline (without using $ref) JsonNullable is generated. A type: [string, "null"] should generate JsonNullable (or Optional) regardless of whether the field is included with allOf or not.

openapi-generator version

I tested this with 7.11.0 with the maven plugin, as well as the 7.13.0 snapshot build above.
I'm upgrading from version 6.6.0, and spec version 3.0 (replacing type: [string, "null"] with type: string and nullable: true), and I see JsonNullable in both cases.

OpenAPI declaration file content or url

Here is my spec, nullableAllOfSpec.yaml

openapi: 3.1.0
info:
  title: Test API
  version: "1.0"

paths:
  /itemsInline:
    get:
      operationId: getInline
      summary: Get a list of items
      description: Retrieves a list of items
      responses:
        default: # creates GetInlineDefaultResponse, with 1 JsonNullable field and one plain String field
          description: Items retrieved
          content:
            application/json:
              schema:
                type: object
                properties:
                  nonNullablePropertyInline:
                    type: string
                  nullablePropertyInline:
                    type: [string, "null"]
  /itemsAllOf:
    get:
      operationId: getAllOf
      summary: Get a list of items
      description: Retrieves a list of items
      responses:
        default: # creates GetAllOfDefaultResponse, with 2 plain String field, even though NullablePropertyList has a JsonNullable property
          description: Items retrieved
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/NullablePropertyList'
                  - $ref: '#/components/schemas/NonNullablePropertyList'
components:
  schemas:
    NullablePropertyList: # Creates NullablePropertyList, with a JsonNullableProperty
      type: object
      properties:
        nullableProperty:
          type: [ string, "null" ]
    NonNullablePropertyList:
      type: object
      properties:
        nonNullableProperty:
          type: string
Generation Details

java -jar openapi-generator-cli-7.13.0-20250307.080352-24.jar generate -i NullableAllOf/src/main/resources/nullableAllOfSpec.yaml -g spring --library 'spring-boot'

Steps to reproduce

Run the generate command in generation details.
Specifically, I expected GetAllOfDefaultResponse.java to have.

  private @Nullable JsonNullable<String> nullableProperty;

  private @Nullable String nonNullableProperty;

instead of

  private @Nullable String nullableProperty;

  private @Nullable String nonNullableProperty;

Also, I'm not sure about the @Nullable annotation from org.springframework.lang.Nullable. I didn't have this in the previous generator and OAS version, but it seems like JsonNullable is still supported and I'd like to continue using that.

Related issues/PRs

Didn't find any

Suggest a fix

I added some comments in nullableDataType.mustache and nullableDataTypeBeanValidation.mustache, and it appears the isNullable flag is not getting set to true when being passed to nullableDataTypeBeanValidation.mustache, but only in the allOf context when generating GetAllOfDefaultResponse. The same comments indicate isNullable is set to true when generating the NullablePropertyList.

I could look into this further and possibly create a PR, but at this point I was looking for confirmation on if this is a bug or something else happened like I missed a configuration.

Activity

  1. changed the title [-][BUG] [java] [spring] type: [string, "null"] isn't[/-] [+][BUG] [java] [spring] type: [string, "null"] isn't generating JsonNullable properties[/+] on Mar 7, 2025
  2. ellioth-vc commented on Mar 25, 2025

    @ellioth-vc

    I'm seeing the same behavior in the typescript-fetch generator. After upgrading from version 7.6.0 to 7.12.0, null types are being dropped in schemas that are constructed with allOf.

    EDIT: For the typescript-fetch generator, it appears this regression was introduced in version 7.7.0.

  3. BarboraCigankova commented on Aug 12, 2026

    @BarboraCigankova

    any chance that this will be fixed?

  4. wing328 commented on Aug 13, 2026

    @wing328
    Member

    just did a test with typescript-fetch using the latest master and the output seems good

    export interface NullablePropertyList {
        /**
         *
         */
        nullableProperty?: string | null;
    }
    
    export interface NonNullablePropertyList {
        /**
         *
         */
        nonNullableProperty?: string;
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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