Bug Report Checklist
Description
When a nullable property is required, the generated class has a non-nullable field and getter.
openapi-generator version
7.24.0
OpenAPI declaration file content or url
This is an example spec that I used to reproduce:
{
"openapi": "3.1.0",
"info": {
"title": "Reproduce",
"version": "1.0.0"
},
"paths": {
"/thing": {
"get": {
"operationId": "getThing",
"responses": {
"200": {
"description": "ok",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Thing"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Thing": {
"type": "object",
"required": [
"name",
"description"
],
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
}
}
}
}
}
Generation Details
Java 17
JAR=openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar
"$JAVA_HOME/bin/java" -jar "$JAR" generate \
-i spec.json \
-g spring \
-o out \
--additional-properties=useJspecify=true,hideGenerationTimestamp=true,openApiNullable=false
Steps to reproduce
Run the generator tool on the spec above with the provided options. Observe that the resulting class does not have the right nullability marks:
public class Thing {
private String name = null; // field should be @Nullable
/**
* Get name
* @return name
*/
@NotNull // wrong annotation, should be @Nullable
@Schema(name = "name", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("name")
public String getName() {
return name;
}
@JsonProperty("name")
public void setName(String name) { // parameter should be @Nullable
this.name = name;
}
Related issues/PRs
#23866
#20827
Bug Report Checklist
Description
When a nullable property is required, the generated class has a non-nullable field and getter.
openapi-generator version
7.24.0
OpenAPI declaration file content or url
This is an example spec that I used to reproduce:
{ "openapi": "3.1.0", "info": { "title": "Reproduce", "version": "1.0.0" }, "paths": { "/thing": { "get": { "operationId": "getThing", "responses": { "200": { "description": "ok", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Thing" } } } } } } } }, "components": { "schemas": { "Thing": { "type": "object", "required": [ "name", "description" ], "properties": { "name": { "anyOf": [ { "type": "string" }, { "type": "null" } ] }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ] } } } } } }Generation Details
Java 17
Steps to reproduce
Run the generator tool on the spec above with the provided options. Observe that the resulting class does not have the right nullability marks:
Related issues/PRs
#23866
#20827