SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
156 stars 25 forks source link

How to document body parameters? #42

Closed ScottPierce closed 3 months ago

ScottPierce commented 1 year ago

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?

SMILEY4 commented 1 year ago

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.

ScottPierce commented 1 year ago

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

SMILEY4 commented 1 year ago

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 commented 1 year ago

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: @.***>

chrimaeon commented 1 year ago

@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