Add mechanism to disable nullable for Kotlin properties#3269
Open
0xabadea wants to merge 1 commit intospringdoc:mainfrom
Open
Add mechanism to disable nullable for Kotlin properties#32690xabadea wants to merge 1 commit intospringdoc:mainfrom
0xabadea wants to merge 1 commit intospringdoc:mainfrom
Conversation
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.
The newly-added
KotlinNullablePropertyCustomizerresults in Kotlin nullable properties being always marked as non-required and nullable. Sometimes that may not be a desirable output.The Java/Kotlin+Jackson ecosystem does not generally or easily support undefined and null properties at the same time. Usually, Kotlin properties with a null value are either serialized as
"property": nullor they are left out (making them undefined). In our backend we leave them out via@JsonIncludenon_null/non_absentand we document them as non-required in our OpenAPI spec. The understanding is that they may be missing from the payload, but if they are present, they are never null.Our frontend then generates TypeScript types with optional properties, as in
property?: TheType. In this setup, marking these properties as nullable in the OpenAPI spec results in optional and nullable TypeScript properties, as inproperty?: TheType | null. This brings no additional value and is actually detrimental, as the frontend developers now need to handle null values that never occur in practice.I propose the introduction of a new property
springdoc.model-converters.kotlin-nullable-property-customizer.enabled(defaulted to true) that would allow disablingKotlinNullablePropertyCustomizeron demand.