The openapi generator should generate JsonNullable<?> type when a property is defined as nullable:true.
I've created the next repository to show the issue: https://github.com/robertop87/opengen
Basically when property defined in swagger.yml has nullable: true, like the next example:
openapi-generator version 7.3.0 (gradle plugin)
tag:
type: string
nullable: true
The generator should generate Java code as:
private JsonNullable<String> tag = JsonNullable.undefined();
But the current result is:
private String tag;
Please take a look in the example repository, maybe I'm doing something wrong or missing something.
Additionally I already reported this issue here: https://github.com/OpenAPITools/openapi-generator/issues/17873
I removed the nullable property, also make a combination with required, in any case I got the expected result.
My generator configuration in gradle.build file is:
tasks.register('generateClient', GenerateTask) {
generatorName.set("java")
inputSpec.set(swaggerFile.toString())
outputDir.set(swaggerOutputDir)
configOptions.set([dateLibrary: "java8", useJakartaEe: "true"])
}
Update 1:
The JsonNullable is being generated properly using
generatorName.set("spring")
But this is to generate a server application, not a client.
Update 2:
According docs there are extension to enable the expected generator behavior, in this case enabling x-is-jackson-optional-nullable: true should be enough, but the generator still doing the same.
Check latest commits in https://github.com/robertop87/opengen
Update 3:
When debugging the openapi-generatod source code, I noticed that JsonNullable is working fine, because the generator's library is configured as WEBCLIENT.
Additional note: x-is-jackson-optional-nullable was not needed in the configuration.
So I configured my generator like this:
tasks.register('generateClient', GenerateTask) {
generatorName.set("java")
library.set("webclient") // only with webclient the JsonNullable is generated properly
inputSpec.set(swaggerFile.toString())
outputDir.set(swaggerOutputDir)
configOptions.set([
dateLibrary: "java8",
useJakartaEe: "true",
openApiNullable: "true" // This is enabled by default
])
}
As result the JsonNullable were generated properly.
But, I'll test a bit more in client side if it's working as expected.