SMILEY4 / ktor-swagger-ui

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

Add support for custom RouteSelector #28

Closed dmitry-oshurkov closed 1 year ago

dmitry-oshurkov commented 1 year ago

Need for implement authorization and etc.

Suggestion:


// add abstract RouteSelector
abstract class TransparentRouteSelector : RouteSelector()

private fun getPath(route: Route): String {
        return when (route.selector) {
            is TrailingSlashRouteSelector -> "/"
            is RootRouteSelector -> ""
            is DocumentedRouteSelector -> route.parent?.let { getPath(it) } ?: ""
            is HttpMethodRouteSelector -> route.parent?.let { getPath(it) } ?: ""
            is AuthenticationRouteSelector -> route.parent?.let { getPath(it) } ?: ""
            is TransparentRouteSelector -> route.parent?.let { getPath(it) } ?: "" // this is new abstract class
            else -> (route.parent?.let { getPath(it) } ?: "") + "/" + route.selector.toString()
        }
    }
SMILEY4 commented 1 year ago

Hi, great suggestion.

i think i would add this functionality as new entry in the plugin config:

install(SwaggerUI) {
    // ignore all route-selectors (or subclasses of them) in the given list
    ignoredRouteSelectors = listOf(YourTransparentRouteSelector::class)
}

Imho, this would be a bit more flexible. I would add this in the next version soon.