io.javalin.openapi.plugin.redoc.ReDocWebJarHandler.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
import org.eclipse.jetty.http.HttpStatus
import org.eclipse.jetty.http.MimeTypes
internal class ReDocWebJarHandler(private val redocWebJarPath: String) : Handler {
override fun handle(context: Context) {
val resource = ReDocPlugin::class.java.getResourceAsStream("/META-INF/resources" + redocWebJarPath + context.path().replaceFirst(context.contextPath(), "").replaceFirst(redocWebJarPath, ""))
if (resource == null) {
context.status(HttpStatus.NOT_FOUND_404)
return
}
context.res().characterEncoding = "UTF-8"
context.result(resource)
MimeTypes.getDefaultMimeByExtension(context.path())?.let {
context.contentType(it)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy