Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do we provide descriptions for parameters? #103

Open
arajendiran opened this issue May 13, 2023 · 1 comment
Open

How do we provide descriptions for parameters? #103

arajendiran opened this issue May 13, 2023 · 1 comment

Comments

@arajendiran
Copy link

arajendiran commented May 13, 2023

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 arajendiran changed the title How do we provide descriptions for parameters. How do we provide descriptions for parameters? May 13, 2023
@jpuerto
Copy link

jpuerto commented Nov 9, 2023

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.

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

No branches or pull requests

2 participants