Repository navigation
Description
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?
Description
With useJspecify=true, the spring generator annotates a nullable property's fluent setter with @Nullable on the model that declares the property, but the fluent override it writes in a subclass (allOf child) has no @Nullable on the same parameter. The model package is @NullMarked, so the override declares the parameter non-null while the method it overrides accepts null. NullAway and other JSpecify checkers report the override, and callers holding a @Nullable String cannot call child.description(value) without a cast or an extra null check.
Actual (Child.java):
public Child description(String description) {
super.description(description);
return this;
}Expected:
public Child description(@Nullable String description) {
super.description(description);
return this;
}Base.java, generated in the same run, is correct:
public Base description(@Nullable String description) {
this.description = description;
return this;
}openapi-generator version
7.27.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: repro
version: 1.0.0
paths: {}
components:
schemas:
Base:
type: object
required: [kind]
properties:
kind:
type: string
description:
type: string
nullable: true
discriminator:
propertyName: kind
Child:
allOf:
- $ref: '#/components/schemas/Base'
- type: object
properties:
extra:
type: stringGeneration Details
openapi-generator-cli generate -i spec.yaml -g spring -o out \
--additional-properties=useJspecify=true,openApiNullable=false,useSpringBoot3=true,interfaceOnly=true,useBeanValidation=true
Steps to reproduce
Reproducer repository: https://github.com/BigMichi1/openapi-generator-jspecify-override-repro
- Save the spec above as
spec.yamland run the command. - Compare
description(...)inout/src/main/java/org/openapitools/model/Base.javaandChild.java;package-info.javacarries@org.jspecify.annotations.NullMarked.
Related issues/PRs
- [BUG][JAVA] Generated code still missing many @Nullable annotations #25536 (other
@Nullableannotations missing underuseJspecify; it coversadditionalPropertiesandequals, not parent-property overrides) - [BUG][Spring] useJspecify=true can emit @Nullable without importing org.jspecify.annotations.Nullable #23848 (
@Nullableemitted without its import underuseJspecify)
Suggest a fix
In JavaSpring/pojo.mustache, the block that re-declares the parent's fluent setters for an allOf child (the one calling super.<name>(...)) could emit the same nullable annotation the parent's setter gets for that variable.
Activity
shu-chen-dot-ca commentedon Nov 27, 2026
I'd like to work on this one and will open a PR shortly.