SMILEY4 / ktor-swagger-ui

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

Problem with a route dsl #6

Closed CristianMG closed 2 years ago

CristianMG commented 2 years ago

Hi, I would like to use this library for my backend. I have a problem because I'm using the route dsl to define the route father.

This causes the dsl doesn't have the appropriate functions or work poorly. Is there any intention to give support for this function?

route("/users") {
        /* Registration: POST /api/users */
        post() {
            either<DomainError, UserWrapper<User>> {
                val (username, email, password) = receiveCatching<UserWrapper<NewUser>>().bind().user
                val token = userService.register(RegisterUser(username, email, password)).bind().value
                UserWrapper(User(email, token, username, "", ""))
            }.respond(HttpStatusCode.Created)
        }
        post("/login") {
            either<DomainError, UserWrapper<User>> {
                val (email, password) = receiveCatching<UserWrapper<LoginUser>>().bind().user
                val (token, info) = userService.login(Login(email, password)).bind()
                UserWrapper(User(email, token.value, info.username, info.bio, info.image))
            }.respond(HttpStatusCode.OK)
        }
    }

Thanks.

SMILEY4 commented 2 years ago

Hi,

i'm not quite sure I completly understand the issue. Could you provide more information about what exactly you're trying to do and which part isn't working?

In theory, you should be able to add the openapi-documentation to your code like this:

import io.github.smiley4.ktorswaggerui.dsl.post
import io.ktor.server.routing.route
import io.ktor.server.routing.routing

...

route("/users") {
    /* Registration: POST /api/users */
    post({
        description = "... description for /users"
    }) {
        //... handle request
    }
    post("/login", {
        description = "... description for /users/login"
    }) {
        //... handle request
    }
}
CristianMG commented 2 years ago

Sorry, you are right, the problem was related to the initiation of the application of the example I was using, I created an example from zero and it seems to work fine. Thanks