kotlin-openapi3-dsl
kotlin-openapi3-dsl copied to clipboard
How do we provide descriptions for parameters?
For a data class defined as follows,
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.media.Schema
// ...
@Schema(description = "Test DateWrapper Description")
data class DateWrapper(
@Parameter(description = "test description")
val startDate: LocalDate,
val endDate: LocalDate? = null,
)
the output of the json is as follows.
"DateWrapper": {
"description": "Test DateWrapper Description",
"type": "object",
"properties": {
"endDate": {
"format": "date",
"type": "string"
},
"startDate": {
"format": "date",
"type": "string"
},
}
},
I am trying to provide a description for the Property (startDate) in the Schema. Could you provide some guidance on how to do achieve this? I am looking for an output as follows:
"DateWrapper": {
"description": "Test DateWrapper Description",
"type": "object",
"properties": {
"endDate": {
"format": "date",
"type": "string"
},
"startDate": {
"format": "date",
"type": "string",
"description" : "test description"
},
}
},
Hi @arajendiran ,
As far as I know, the annotations used are for Java and for kotlin we need to specify the target of the annotation in the generated java code. See https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets
Perhaps you can try with the following snippet:
@Schema(description = "Test DateWrapper Description")
data class DateWrapper(
@field:Schema(description = "test description")
val startDate: LocalDate,
val endDate: LocalDate? = null,
)
It is working for me to customise format or validation for specific attributes, at the end it is using ModelConverters.