diff --git a/README.md b/README.md index 134458f..68da471 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,14 @@ A wiki with a short documentation is available [here](https://github.com/SMILEY4 1. Add the JitPack repository ```kotlin repositories { - maven { url "https://jitpack.io" } + maven { url = uri("https://jitpack.io") } } ``` + 2. Add the dependency ```kotlin dependencies { - implementation 'io.github.smiley4:ktor-swagger-ui:' + implementation "io.github.smiley4:ktor-swagger-ui:" } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 5297ab1..9ad1996 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "io.github.smiley4" -version = "1.4.0" +version = "1.5.0" repositories { mavenCentral() diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/OpenApiRoute.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/OpenApiRoute.kt index 30f75d1..ccd7286 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/OpenApiRoute.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/OpenApiRoute.kt @@ -34,6 +34,12 @@ class OpenApiRoute { var deprecated: Boolean = false + /** + * Whether this route is hidden. + */ + var hidden: Boolean = false + + /** * A declaration of which security mechanism can be used for this operation. * If not specified (and none specified with [securitySchemeNames]), defaultSecuritySchemeName (global plugin config) will be used diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiPathsBuilder.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiPathsBuilder.kt index 76ca9fe..7f293e2 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiPathsBuilder.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiPathsBuilder.kt @@ -21,15 +21,14 @@ class OApiPathsBuilder(private val routeCollector: RouteCollector) { .filter { removeLeadingSlash(it.path) != removeLeadingSlash("${config.getSwaggerUI().swaggerUrl}/api.json") } .filter { removeLeadingSlash(it.path) != removeLeadingSlash("${config.getSwaggerUI().swaggerUrl}/{filename}") } .filter { !config.getSwaggerUI().forwardRoot || it.path != "/" } + .filter { !it.documentation.hidden } .filter { path -> config.pathFilter ?.let { it(path.method, path.path.split("/").filter { it.isNotEmpty() }) } ?: true } .onEach { logger.debug("Configure path: ${it.method.value} ${it.path}") } - .map { - pathBuilder.build(it, components, config) - } + .map { pathBuilder.build(it, components, config) } .forEach { addToPaths(this, it.first, it.second) } } } diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/RouteCollector.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/RouteCollector.kt index 3131dbf..cafadda 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/RouteCollector.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/RouteCollector.kt @@ -107,6 +107,7 @@ class RouteCollector { b.securitySchemeNames?.let { merged.addAll(it) } } deprecated = a.deprecated || b.deprecated + hidden = a.hidden || b.hidden request { (getParameters() as MutableList).also { it.addAll(a.getRequest().getParameters()) diff --git a/src/test/kotlin/io/github/smiley4/ktorswaggerui/examples/CompleteExample.kt b/src/test/kotlin/io/github/smiley4/ktorswaggerui/examples/CompleteExample.kt index cfb9a8c..17cd958 100644 --- a/src/test/kotlin/io/github/smiley4/ktorswaggerui/examples/CompleteExample.kt +++ b/src/test/kotlin/io/github/smiley4/ktorswaggerui/examples/CompleteExample.kt @@ -21,6 +21,7 @@ import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.request.receive import io.ktor.server.response.respond import io.ktor.server.response.respondText +import io.ktor.server.routing.get import io.ktor.server.routing.routing import java.util.Random @@ -249,5 +250,12 @@ private fun Application.myModule() { } + get("hidden", { + hidden = true + description = "This route is hidden and not visible in swagger" + }){ + call.respond(HttpStatusCode.NotImplemented, "todo") + } + } } \ No newline at end of file