SMILEY4 / ktor-swagger-ui

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

Doesn't work correctly with RateLimit Plugin #86

Closed EchoEllet closed 5 months ago

EchoEllet commented 5 months ago

When using Ktor Server RateLimit from the Ktor team, it won't work as it will make the URL invalid

Example code:

Installing the RateLimit plugin and configuring it


install(RateLimit) {
        global {
            rateLimiter(limit = 50, refillPeriod = 1.minutes)
        }
        register(RateLimitName("auth")) {
            rateLimiter(limit = 20, refillPeriod = 5.minutes)
        }
    }

Register the rateLimit for any route


rateLimit(RateLimitName("auth")) {
            route("/auth") {
                signUpWithEmailAndPassword()
                signInWithEmailAndPassword()
                verifyEmail()
                deleteSelfAccount()
            }
        }

image

When I send a request it send 404 because the URL is not correct because of the RateLimit auth in the URL path

SMILEY4 commented 5 months ago

Hi, you can ignore the rate-limit part in the url by adding it to the ignored selectors in the plugin config

install(SwaggerUI) {
    ignoredRouteSelectors += RateLimitRouteSelector::class
}

I'll also probly add ignore it by default in some future version.

EchoEllet commented 5 months ago

Hi, you can ignore the rate-limit part in the url by adding it to the ignored selectors in the plugin config

install(SwaggerUI) {
  ignoredRouteSelectors += RateLimitRouteSelector::class
}

I'll also probly add ignore it by default in some future version.

Thanks. Also, it would be nice (even though it's difficult and unlikely to happen) to generate the route info like description from the route comments just like in javascript