Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed May 19, 2024
2 parents b37efaa + f0a2ad7 commit 425236e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)}" } ?: ""
}
Expand Down

0 comments on commit 425236e

Please sign in to comment.