SMILEY4 / ktor-swagger-ui

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

How to Turn Off Swagger-ui in Production? #79

Closed x2d7751347m closed 8 months ago

x2d7751347m commented 8 months ago

https://www.baeldung.com/swagger-ui-turn-off-in-production This is an example of spring. And I want to know how to turn off/hide swagger UI in production.

I'm using it this way, but it doesn't seem to be the proper way.

install(SwaggerUI) {
        ignoredRouteSelectors = ignoredRouteSelectors + RateLimitRouteSelector::class
        swagger {
            swaggerUrl = "swagger-ui"
            forwardRoot = true
        }
        info {
            title = "API"
            version = "latest"
            description = "API"
        }
        server {
            // Some features are disabled, but the UI is still visible.
            url = "a"
            description = "Development Server"
        }
SMILEY4 commented 8 months ago

Hi, you can completly distable swagger by not installing it in "production mode":

if(!prodMode) {
    install(SwaggerUI) { /*...*/ }
}