revert: auto-set nullable for Kotlin nullable types (#3256)#3276
Open
thejeff77 wants to merge 1 commit intospringdoc:mainfrom
Open
revert: auto-set nullable for Kotlin nullable types (#3256)#3276thejeff77 wants to merge 1 commit intospringdoc:mainfrom
thejeff77 wants to merge 1 commit intospringdoc:mainfrom
Conversation
Contributor
Author
|
Cross-link: the upstream |
This was referenced Apr 23, 2026
Contributor
Author
|
Note on CI: the failing `Java CI with Maven` check (`Non-resolvable parent POM for org.springdoc:springdoc-openapi-tests`) is pre-existing infrastructure, not caused by this revert. Same exact failure on:
This PR is a literal `git revert -m 1` of the #3256 merge commit — no manual conflict resolution, no test changes beyond the original PR's tests being deleted alongside the customizer they covered. The same code (pre-#3256) was passing CI before #3256 was introduced. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reverts #3256. The
KotlinNullablePropertyCustomizerauto-marks KotlinT?as nullable with no per-property opt-out, which silently produces incorrect specs for backends using@JsonInclude(NON_NULL). This restores pre-#3256 behavior pending an upstreamNullableModeproposal in swagger-core.Why revert rather than patch
The customizer auto-marks any Kotlin
T?property as nullable in the generated schema. This is correct only when Jackson actually serializes null values onto the wire — i.e., default Jackson configuration. For backends that use@JsonInclude(NON_NULL)(a widespread Jackson convention) the resulting spec is wrong: it claims null can appear when in fact Jackson strips null fields entirely.The natural per-property override would be
@Schema(nullable = false). This cannot be honored.@Schema.nullable()is abooleandefaulting tofalse, which means via reflection there is no way to distinguish "user explicitly wrotenullable = false" from "user never specified anything." This is a known design wart on@Schema's legacy boolean fields — the same issue swagger-core addressed forrequiredby introducingRequiredModein 2022 (swagger-api/swagger-core#4221, swagger-api/swagger-core#4286, commitb1729fcf1) and forreadOnly/writeOnlyby introducingAccessModein 2018 (swagger-api/swagger-core#2675, swagger-api/swagger-core#2677). No equivalentNullableModeexists yet.Without that override, this PR's auto-detection cannot be made correct for the population it impacts. A global enable/disable flag (proposed in #3269) addresses the symptom but not the underlying override gap — codebases that mix
@JsonInclude(NON_NULL)and default-Jackson DTOs still have no clean answer, and shipping the flag adds global config surface for a problem that will be solved per-property upstream onceNullableModeexists.Path forward
@field:Schema(nullable = true)annotation, the long-standing workaround they were using before feat: auto-set nullable: true for Kotlin nullable types in schema properties #3256.NullableMode { AUTO, NULLABLE, NOT_NULLABLE }mirroringRequiredMode. Issue/PR to be opened on swagger-api/swagger-core. This benefits both layers — the swagger-core@Nullableauto-detection added in 5001: Add support for @Nullable annotations in OpenAPI 3.1 schemas swagger-api/swagger-core#5018 (2025-11) hits the same override gap and would also use the new mode.KotlinNullablePropertyCustomizeronceNullableModeships upstream, with the customizer honoringNullableMode.NOT_NULLABLEas an explicit per-property override andNullableMode.AUTO(default) as the auto-detection trigger.Background discussions
@Nullablesupport), [Bug]: Issues using @Nullable annotations in OpenAPI 3.1 schemata swagger-api/swagger-core#5077, [Bug]: Wrong schema for nullable object swagger-api/swagger-core#5158, fix: ensure that @Nullable does not incorrectly affect object schemas swagger-api/swagger-core#5124Test plan
val foo: String? = nullno longer auto-marks asnullable: true(back to pre-feat: auto-set nullable: true for Kotlin nullable types in schema properties #3256 behavior)@field:Schema(nullable = true)opt-in still worksRisk
Low. This is a literal
git revertof the merge commit; no manual conflict resolution. Users relying on the auto-detection lose it and must re-add@field:Schema(nullable = true)until the upstreamNullableModework lands.