From 7474d0979e0e01a013e9aa441f0266f5814d7921 Mon Sep 17 00:00:00 2001 From: Lukas Ruegner Date: Wed, 8 Jan 2025 22:17:32 +0100 Subject: [PATCH] hide swagger routes --- .../smiley4/ktoropenapi/builder/route/RouteCollector.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/builder/route/RouteCollector.kt b/ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/builder/route/RouteCollector.kt index d3aefbb..c192a2a 100644 --- a/ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/builder/route/RouteCollector.kt +++ b/ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/builder/route/RouteCollector.kt @@ -1,8 +1,8 @@ package io.github.smiley4.ktoropenapi.builder.route import io.github.smiley4.ktoropenapi.data.OpenApiPluginData -import io.github.smiley4.ktoropenapi.dsl.routing.DocumentedRouteSelector import io.github.smiley4.ktoropenapi.dsl.routes.RouteConfig +import io.github.smiley4.ktoropenapi.dsl.routing.DocumentedRouteSelector import io.ktor.http.HttpMethod import io.ktor.server.auth.AuthenticationRouteSelector import io.ktor.server.routing.ConstantParameterRouteSelector @@ -22,6 +22,11 @@ internal class RouteCollector { private val routeDocumentationMerger = RouteDocumentationMerger() + private val hiddenRouteMarkers = setOf( + "io.github.smiley4.ktorswaggerui.SwaggerUIRouteSelector" + ) + + /** * Collect all routes from the given application */ @@ -38,6 +43,7 @@ internal class RouteCollector { ) } .filter { !it.documentation.hidden } + .filter { path -> hiddenRouteMarkers.none { path.path.contains(it) } } .filter { path -> config.pathFilter(path.method, path.path.split("/").filter { it.isNotEmpty() }) } .toList() }