Skip to content

feat: add JavaNullablePropertyCustomizer to handle nullable properties in OpenAPI schemas - #3382

Merged
bnasslahsen merged 1 commit into
springdoc:mainfrom
Mattias-Sehlstedt:java-nullable-customizer
Oct 23, 2026
Merged

bnasslahsen merged 1 commit into
springdoc:mainfrom
Mattias-Sehlstedt:java-nullable-customizer

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Implements the existing behavior from Kotlin with nullability (KotlinNullablePropertyCustomizer) resolving for ref:s in Java.

Note that this behavior is configurable, and that it is opt-in. So there should be no issues with consumers getting a surprise behavior that they cannot easily disable.

This feature also already considers a missing case for nullability that has been handled in #3381 for Kotlin.

The expectation is that this logic will later live in swagger-core, see for example swagger-api/swagger-core#5077 (comment). But until then it would be helpful to provide the behavior here.

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the java-nullable-customizer branch 2 times, most recently from 4ed6e2c to 1532763 Compare October 8, 2026 18:40
@Mattias-Sehlstedt Mattias-Sehlstedt changed the title feat: Add JavaNullablePropertyCustomizer to handle nullable properties in OpenAPI schemas feat: add JavaNullablePropertyCustomizer to handle nullable properties in OpenAPI schemas Oct 8, 2026
@bnasslahsen
bnasslahsen merged commit 4afe01d into springdoc:main Oct 23, 2026
1 check passed
bnasslahsen pushed a commit that referenced this pull request Oct 23, 2026
JavaNullablePropertyCustomizer marks the properties of Java models
annotated with @nullable as nullable, on the field, the getter or the
constructor parameter, including $ref and oneOf properties. It is
enabled with springdoc.model-converters.java-nullable-property-customizer.enabled.
The schema handling is shared with KotlinNullablePropertyCustomizer in
AbstractNullablePropertyCustomizer.

Backport of gh-3382

Signed-off-by: Badr NASS LAHSEN <badr.nasslahsen@gmail.com>
@bnasslahsen

Copy link
Copy Markdown
Collaborator

Thanks @Mattias-Sehlstedt! Merged with a follow-up, keeping your tests (moved to app279/app280): the schema handling is now shared with KotlinNullablePropertyCustomizer in a new AbstractNullablePropertyCustomizer, so the two customizers only differ in how they find their nullable properties and can't drift apart again. Backported to spring-boot-3 (173a77f).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants