Closed Skater901 closed 1 month ago
Could you provide an example of how you define the models with annotations on constructor parameters? I'm not sure i completely understand correctly. Thank you :D
Sure, here's an example from code I'm actually working on:
@Schema(description = "The username (or email address) and password to login with.")
@JsonDeserialize
@JsonIgnoreProperties(ignoreUnknown = true)
data class LoginRequest(
@Schema(
description = "The username or email address of the SWAT account you wish to log in to.",
example = "Test User"
)
@field:NotBlank
@field:Size(max = 100)
@JsonProperty("username", required = true)
val username: String?,
@Schema(
description = "The password for the SWAT account you wish to log in to.",
example = "password123"
)
@field:NotBlank
@field:Size(max = 100)
@JsonProperty("password", required = true)
val password: String?
)
It's basically used for request objects; I put @JsonProperty
annotations on the properties with specific names, so if I decide to refactor the property name internally, the JSON annotation still has the same property name, and I don't accidentally break my API by renaming. But as far as I can tell, these annotations aren't picked up by the schema-kenerator-jackson
library, because the schema-kenerator-reflection
library doesn't pick up the annotations that are targeting constructor params.
Specifically, I'm talking about this stuff: https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets
I want the annotations that target @param:
to be included. :) (Targeting @param:
is the default for annotations on properties in the constructor, as far as I know)
Thanks. annotations on constructor parameters will now be included with the next version. See testcase: https://github.com/SMILEY4/schema-kenerator/blob/c127bb7cd50dbe9314da17128f8bf7ca4a04f1d1/schema-kenerator-test/src/test/kotlin/io/github/smiley4/schemakenerator/test/MiscTests.kt#L200
From digging into the code, and my own usage of this library, as far as I can tell, constructor parameters aren't inspected for annotations when generating the schema. This sucks, because when I'm creating request objects with Jackson, I put annotations on the constructor parameters, NOT the fields. But only the fields are inspected by the code. This means if I have a different property name in my Jackson annotation compared to the actual field name, the generated schema will use the internal field name, and not the value Jackson will look for when deserializing.
It'd be great if constructor parameters could also be considered when generating the schema. :)