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

@Description annotation doesn't work #123

Open
greekZorba opened this issue Jan 20, 2022 · 3 comments
Open

@Description annotation doesn't work #123

greekZorba opened this issue Jan 20, 2022 · 3 comments

Comments

@greekZorba
Copy link

greekZorba commented Jan 20, 2022

I am trying to use @Description to my schema model.

my version is 0.3-beta.2

But nothing happen to my schema model.

Am I using @Description annotation incorrectly? Or @Description is working improperly?

this is my code as shown below.

can I get any advice?

  fun NormalOpenAPIRoute.regionSpec() {
  
          route("/api/regions") {
              get<Unit, RegionResponse>(
                  info("show regions")
              ) {
                  respond(RegionResponse.of("seoul", 1, "seoul city"))
              }        
  }
      @Response("Region")
      data class RegionResponse(
          @Description("city") val sido: String,
          @Description("region id") val regionId: Int,
          @Description("region name") val region: String
      ) : Serializable {
          companion object {
              fun of(sido: String, regionId: Int, region: String) =
                  RegionResponse(sido = sido, regionId = regionId, region = region)
          }
      }
    "components" : {
        "schemas" : {
          "RegionResponse" : {
            "nullable" : false,
            "properties" : {
              "region" : {
                "nullable" : false,
                "type" : "string"
              },
              "regionId" : {
                "format" : "int32",
                "nullable" : false,
                "type" : "integer"
              },
              "sido" : {
                "nullable" : false,
                "type" : "string"
              }
            },
            "required" : [ "region", "regionId", "sido" ],
            "type" : "object"
          }
       }
    }
@Wicpar
Copy link
Collaborator

Wicpar commented Feb 27, 2022

It should work, maybe you can try to annotate the type instead. I'll look into it when i have a bit of time

@craigberry1
Copy link

Any chance you've taken a look at this @Wicpar? Seeing same behavior.

@janhaesen
Copy link

janhaesen commented Dec 27, 2022

I'm not fully aware yet why, but the reason it's not working is that you can't get by with just adding the annotation. You need to explicitly annotate it as: @property:Description, which will make the code pick it up properly. This wasn't an issue before as the only target set was property. This was changed where it's now applicable to both property and a value parameter.

Perhaps whoever is more aware of the inner workings of Kotlin reflection can shed some more light on why this is the case. I've yet to grasp it 100%.

EDIT: it is explained here https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets

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

4 participants