swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

kotlin field annotated by @Schema(required = false, defaultValue = "") recognized as required

Open rainmanhhh opened this issue 5 years ago • 2 comments

class Foo
    @Schema(required = false, defaultValue = "")
    var bar: String = ""
}

rainmanhhh avatar Jul 15 '20 02:07 rainmanhhh

I was facing the same problem (with an optional boolean in a @ReponseBody data class), and the only way to make it not required in the schema was to make it nullable (which it should not be):

data class Body(
    @get:Schema(required = false) //this doesn't work
    val verified: Boolean? = false //as Boolean it's required even with a default value, as Boolean? it's not required
)

darioseidl avatar Aug 13 '21 14:08 darioseidl

I was facing the same issue with attempting to update the Swagger docs to be required = false since I would think that it should be possible to override the Swagger docs on specific values you know are not required 🤔 Thank you @darioseidl for a simple fix! 👏

chrisatrotter avatar Aug 10 '22 11:08 chrisatrotter