SMILEY4 / ktor-swagger-ui

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

Response and request models did not create #39

Closed ihaydinn closed 1 year ago

ihaydinn commented 1 year ago

When i launch the application, the swagger file created but did not show response and request body models Screen Shot 2023-04-07 at 01 03 05

SMILEY4 commented 1 year ago

Hi, it's hard to tell whats going on without some more information. Could you mabye provide some code and/or a description of what you did and already tried ?

ihaydinn commented 1 year ago

Hello again. I want to add swagger document for ktor. I added the smiley4 swagger library to my ktor project by following the steps in the readme section. When I did run, only a document like the one I added above came up. No sample documentation for response or request body. Should I follow a different path?

My route example like this.

fun Application.ledgerRoute(repository: LedgerRepository) {
    routing {
        authenticate {
            post("ledger") {
                val principal = call.principal<UserIdPrincipalForUser>()

                val model = call.receive<LedgerRequestModel>()
                val result = repository.addTransaction(model.copy(userId = principal?.id.orZero))
                call.respond(result)
            }
        }
    }
}

and implementation

install(SwaggerUI) {
        swagger {
            swaggerUrl = "swagger-ui"
            forwardRoot = true
        }
        info {
            title = "Example API"
            version = "latest"
            description = "Example API for testing and demonstration purposes."
        }
        server {
            url = "http://localhost:8080"
            description = "Development Server"
        }
    }
    maven ( url = "https://jitpack.io" )
 implementation("io.github.smiley4:ktor-swagger-ui:1.4.0")
SMILEY4 commented 1 year ago

the swagger-plugin does not know the details of the requests and responses of your routes automatically, you have to specify the details yourself. For information on how to do that, you can check out the wiki or look at some of the examples.

ihaydinn commented 1 year ago

yes, exactly this. thank you