diff --git a/build.gradle.kts b/build.gradle.kts index 71a8d91..757ed3c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ import io.gitlab.arturbosch.detekt.Detekt object Meta { const val groupId = "io.github.smiley4" const val artifactId = "ktor-swagger-ui" - const val version = "2.9.0" + const val version = "2.10.0" const val name = "Ktor Swagger-UI" const val description = "Ktor plugin to document routes and provide Swagger UI" const val licenseName = "The Apache License, Version 2.0" diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt index b3977bf..559423d 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt @@ -14,6 +14,7 @@ import io.github.smiley4.ktorswaggerui.builder.schema.TypeOverwrites import io.github.smiley4.ktorswaggerui.data.PluginConfigData import io.github.smiley4.ktorswaggerui.dsl.PluginConfigDsl import io.github.smiley4.ktorswaggerui.routing.ApiSpec +import io.github.smiley4.ktorswaggerui.routing.ControllerUtils import io.github.smiley4.ktorswaggerui.routing.ForwardRouteController import io.github.smiley4.ktorswaggerui.routing.SwaggerController import io.ktor.server.application.* @@ -44,6 +45,7 @@ val SwaggerUI = createApplicationPlugin(name = "SwaggerUI", createConfiguration } try { + ControllerUtils.appConfig = applicationConfig val routes = routes(application, config) ApiSpec.setAll(buildOpenApiSpecs(config, routes)) } catch (e: Exception) { diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/builder/openapi/PathsBuilder.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/builder/openapi/PathsBuilder.kt index 46a3c6e..60a2f15 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/builder/openapi/PathsBuilder.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/builder/openapi/PathsBuilder.kt @@ -1,6 +1,7 @@ package io.github.smiley4.ktorswaggerui.builder.openapi import io.github.smiley4.ktorswaggerui.builder.route.RouteMeta +import io.github.smiley4.ktorswaggerui.routing.ControllerUtils import io.swagger.v3.oas.models.PathItem import io.swagger.v3.oas.models.Paths @@ -21,7 +22,8 @@ class PathsBuilder( } private fun addAsNewPath(paths: Paths, route: RouteMeta) { - paths.addPathItem(route.path, pathBuilder.build(route)) + val rootPath = ControllerUtils.appConfig?.let { ControllerUtils.getRootPath(it) } ?: "" + paths.addPathItem("$rootPath${route.path}", pathBuilder.build(route)) } private fun addToExistingPath(existing: PathItem, route: RouteMeta) { diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ControllerUtils.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ControllerUtils.kt index bb99093..715e23b 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ControllerUtils.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ControllerUtils.kt @@ -1,9 +1,11 @@ package io.github.smiley4.ktorswaggerui.routing -import io.ktor.server.config.ApplicationConfig +import io.ktor.server.config.* object ControllerUtils { + var appConfig: ApplicationConfig? = null + fun getRootPath(appConfig: ApplicationConfig): String { return appConfig.propertyOrNull("ktor.deployment.rootPath")?.getString()?.let { "/${dropSlashes(it)}" } ?: "" }