kotlin-openapi3-dsl icon indicating copy to clipboard operation
kotlin-openapi3-dsl copied to clipboard

How do we provide descriptions for parameters?

Open arajendiran opened this issue 2 years ago • 1 comments

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"
          },
        }
      },

arajendiran avatar May 13 '23 21:05 arajendiran

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.

jpuerto avatar Nov 09 '23 12:11 jpuerto