Skip to content

fix: kotlin nullable composed schema - #3381

Open
itd-sw wants to merge 2 commits into
springdoc:mainfrom
itd-sw:fix/kotlin-nullable-composed-schema
Open

itd-sw wants to merge 2 commits into
springdoc:mainfrom
itd-sw:fix/kotlin-nullable-composed-schema

Conversation

@itd-sw

@itd-sw itd-sw commented Oct 8, 2026

Copy link
Copy Markdown

Summary

Preserve nullability for nullable Kotlin properties represented by a
oneOf schema.

The Any? handling introduced in #3339 identifies schemas without a
direct $ref, type, or types constraint as unconstrained schemas.
However, composed oneOf schemas also lack those fields. They are
therefore mistaken for Any schemas and returned without applying
Kotlin nullability.

This causes nullable composed properties to be generated incorrectly:

  • OpenAPI 3.0 omits nullable: true.
  • OpenAPI 3.1 omits the { "type": "null" } alternative.

Treat oneOf as a schema constraint so these properties are no longer
classified as unconstrained schemas. For OpenAPI 3.1, add a null
alternative to the existing oneOf. For OpenAPI 3.0, allow the existing
nullable: true handling to apply.

Tests

Extend the Kotlin WebMVC snapshot tests with a nullable sealed-class
property for both OpenAPI 3.0 and OpenAPI 3.1.

The commits are separated so the first records the existing incorrect
output and the second applies the fix and updates the expected output.

mvn \
  -pl springdoc-openapi-tests/springdoc-openapi-kotlin-webmvc-tests \
  -am \
  -Dtest=SpringDocApp18Test,SpringDocApp23Test \
  -Dsurefire.failIfNoSpecifiedTests=false \
  test

This branch has not been deployed

No deployments
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.

1 participant