How to document body parameters?
ScottPierce opened this issue · comments
Thank you for providing this library! It's very clean.
How would I describe a Body parameter, and what the acceptable values are for it?
body<ExampleRequest> {
required = true
}
Lets say that ExampleRequest has a parameter limit
that has a max value of 100
. Or if I wanted to document the acceptable formats for a Date String that was sent. Is that possible currently?
Hi,
Thanks. You can customize the schema-objects with the @Schema
-annotation and add for example add the annotation on the limit-field and set the maximum
-property. You can find more information here: https://github.com/SMILEY4/ktor-swagger-ui/wiki/Documenting-Routes-(Bodies)#swagger-schema-annotation.
@SMILEY4 The models are multiplatform models that are shared between platforms. I can't put annotations on them. Is there another way that I can do this?
Unfortunately, there is currently no other way besides annotations.
I'm currently in the process of rewriting the code responsible for handling schemas and objects, so that (describing attributes without annotations/touching the model) might be something i could add in the future.
@ScottPierce I've found a workaround for now. You can create your own "schema generation module". have a look at
https://github.com/chrimaeon/curriculumvitae/blob/2f206be18e0ffb25bced113c2ddf24e67cc97a6f/backend/src/main/kotlin/com/cmgapps/ktor/curriculumvitae/infra/victools/CustomModule.kt
and
https://github.com/chrimaeon/curriculumvitae/blob/2f206be18e0ffb25bced113c2ddf24e67cc97a6f/backend/src/main/kotlin/com/cmgapps/ktor/curriculumvitae/Application.kt#L177