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.
Bug Report Checklist
See below
https://apitools.dev/swagger-parser/online no longer works, so I used https://oas-validation.com/
I used openapi-generator-cli-7.13.0-20250307.080352-24.jar from sonatype
I've read many issues about nullable and type: 'null', I don't think there is an open issue for this.
See below
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.yamlGeneration 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.
instead of
Also, I'm not sure about the
@Nullableannotation 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.