org.http4k.contract.ui.RedocConfig.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-contract Show documentation
Show all versions of http4k-contract Show documentation
http4k typesafe HTTP contracts and OpenApi support
package org.http4k.contract.ui
import org.http4k.core.Filter
data class RedocConfig(
var pageTitle: String = "Redoc",
var url: String = "https://petstore.swagger.io/v2/swagger.json",
val options: MutableMap = mutableMapOf()
)
fun RedocConfig.toFilter(bundleUrl: String) = Filter { next ->
{ req ->
next(req).let { resp ->
resp.body(
resp.bodyString()
.replace("%%DESCRIPTION_ROUTE%%", url)
.replace("%%PAGE_TITLE%%", pageTitle)
.replace("%%BUNDLE_URL%%", bundleUrl)
.replace("%%OPTIONS%%", options.map { (key, value) -> "$key=\"$value\"" }.joinToString(" "))
)
}
}
}