ktor-swagger-ui icon indicating copy to clipboard operation
ktor-swagger-ui copied to clipboard

How to document body parameters?

Open ScottPierce opened this issue 2 years ago • 5 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?

ScottPierce avatar May 12 '23 15:05 ScottPierce

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 avatar May 15 '23 08:05 SMILEY4

@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?

ScottPierce avatar May 15 '23 12:05 ScottPierce

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.

SMILEY4 avatar May 15 '23 12:05 SMILEY4

That would be great! This is the only well written library like this for ktor!

On Mon, May 15, 2023 at 8:43 AM SMILEY4 @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/SMILEY4/ktor-swagger-ui/issues/42#issuecomment-1547792182, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGUWAO6CKHQDSBKDABI453XGIQIFANCNFSM6AAAAAAX7VUFXQ . You are receiving this because you authored the thread.Message ID: @.***>

ScottPierce avatar May 15 '23 13:05 ScottPierce

@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

chrimaeon avatar Jul 30 '23 13:07 chrimaeon