io.javalin.openapi.plugin.redoc.ReDocHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javalin-redoc-plugin Show documentation
Show all versions of javalin-redoc-plugin Show documentation
Serve ReDoc UI for OpenAPI specification
package io.javalin.openapi.plugin.redoc
import io.javalin.http.Context
import io.javalin.http.Handler
/**
* Based on https://github.com/tipsy/javalin/blob/master/javalin-openapi/src/main/java/io/javalin/plugin/openapi/ui/ReDocRenderer.kt by @chsfleury
*/
class ReDocHandler(
private val title: String,
private val documentationPath: String,
private val version: String,
private val routingPath: String,
private val basePath: String?
) : Handler {
override fun handle(context: Context) {
context
.html(createReDocUI())
.res().characterEncoding = "UTF-8"
}
private fun createReDocUI(): String {
val rootPath = (basePath ?: "") + routingPath
val publicBasePath = "$rootPath/webjars/redoc/$version".removedDoubledPathOperators()
val publicDocumentationPath = (rootPath + documentationPath).removedDoubledPathOperators()
return """
|
|
|
| $title
|
|
|
|
|
|
|
|
|
|
|
|
|
|""".trimMargin()
}
private val multiplePathOperatorsRegex = Regex("/+")
private fun String.removedDoubledPathOperators(): String =
replace(multiplePathOperatorsRegex, "/")
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy