Springdoc-openapi: Support for non-nullable types in Kotlin

Created on 18 Feb 2020  路  8Comments  路  Source: springdoc/springdoc-openapi

NB: This is a more specific continuation of issue #269

When generating apidocs from Kotlin data classes the non-nullable fields are not listed as required.

data class Person(
    val name: String
    val nickname: String?
)

The name property should be in the required list:

"Person": {
        "required": [
          "name"
        ],
...

There are workarounds like annotating the non-nullable properties with javax.validation.NotNull, but that is too verbose to my taste.

Most helpful comment

Hi @bnasslahsen ,

It seems to work for function parameters, but not on the response data classes in the components.schemas section of the openapi document.
Can you reopen the issue?

Kind regards, Frank.

All 8 comments

Hi @frank-van-eerden,

The support for non-nullable types in Kotlin will be available on v1.2.32.

Hi @bnasslahsen ,

It seems to work for function parameters, but not on the response data classes in the components.schemas section of the openapi document.
Can you reopen the issue?

Kind regards, Frank.

I noticed that if a class is wrapped within an EntityModel, then it is not able to show non-nullable fields as required. This might be related to #453 .

It seems that it does not work for request body parameters and responses wrapped with ResponseEntity

It also does not work for fields with complex types (e.g. another data class)

@bnasslahsen is it possible to re-open this issue?

@maapteh,

It's all time possible to reopen an issue.
Do you have any additional PR or enhancements to propose?

Unfortunately i have zero PR's in the making. Im just yelling at my backend people :)

"It seems to work for function parameters, but not on the response data classes in the components.schemas section of the openapi document."

Was this page helpful?
0 / 5 - 0 ratings