Skip to content

Add mechanism to disable nullable for Kotlin properties#3269

Open
0xabadea wants to merge 1 commit intospringdoc:mainfrom
0xabadea:feature/disable-kotlin-nullable
Open

Add mechanism to disable nullable for Kotlin properties#3269
0xabadea wants to merge 1 commit intospringdoc:mainfrom
0xabadea:feature/disable-kotlin-nullable

Conversation

@0xabadea
Copy link
Copy Markdown

The newly-added KotlinNullablePropertyCustomizer results 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": null or they are left out (making them undefined). In our backend we leave them out via @JsonInclude non_null/non_absent and 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 in property?: 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 disabling KotlinNullablePropertyCustomizer on demand.

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