Add mechanism to disable nullable for Kotlin properties#3269
Conversation
|
This is highly anticipated 😉 |
|
For visibility on the wider plan: rather than landing a global flag for the customizer, I've proposed reverting #3256 (#3276) and adding a proper per-property override upstream in swagger-core.
Rationale (full discussion on #3256): a global flag addresses the symptom, but the deeper bug is that users have no way to opt a single property out of auto-detection — and |
|
Hello @bnasslahsen, this PR has not been getting any attention so far. Is there anything I can do to get merged either this or #3276 before the next version is released? |
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.