Hi all, we are using http4k-contract and we were w...
# http4k
e
Hi all, we are using http4k-contract and we were wondering if there is a way to add a description to a definition property. As the properties are inferred from the response data class, we thought perhaps there is an annotation or equivalent that we could use?
d
sorry - there isn't a way currently to do this. Although you're correct that theoretically it could be done by us creating a custom annotation and then reflecting on it.
e
Thanks David, do you think this a feature that makes sense to add? I would be happy to help if needed
d
There are 2 bits to it really - the first is simple (the annotation), the second a bit more fiddly (which is the generation of the JsonSchema - would involve reflecting over the annotations on the class to get the information out). This is a list of the properties that are supported on each object property: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject I presume that you'd be targeting the "title" property in that set. We could extend this to have many things as well from the above set (although enum and required are already handled through the type-system). In the code, this would translate to a new (set of?) Annotations, and modifying a reasonable amount of code in the
AutoJsonToJsonSchema.kt
and
FieldRetrieval
files
e
Yes, I was thinking of targeting the title to begin with although the description has the advantage of accepting rich text so it could be useful too in some projects. I think a single annotation approach that would look like this would be good:
Copy code
data class Beany(@Property(title="this cannot be null") val nonNullable: String = "hello",
                 @Property(title="this can be if you want to") val aNullable: String? = "aNullable")
Not sure what the best name for the annotation would be but I can give it a go when I have a bit of time and send you a PR if that is ok