All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sttp.tapir.redoc.akkahttp.RedocAkkaHttp.scala Maven / Gradle / Ivy

package sttp.tapir.redoc.akkahttp

import akka.http.scaladsl.model.{ContentTypes, HttpCharsets, HttpEntity, MediaType, StatusCodes}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route

class RedocAkkaHttp(title: String, yaml: String, yamlName: String = "docs.yaml", redocVersion: String = "2.0.0-rc.23") {
  lazy val html: String =
    s"""
       |
       |
       |
       |  ${title}
       |  
       |  
       |  
       |  
       |
       |  
       |  
       |
       |
       |
       |
       |
       |
       |""".stripMargin

  def routes: Route = {
    get {
      concat(
        pathEnd {
          redirectToTrailingSlashIfMissing(StatusCodes.MovedPermanently) {
            complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, html))
          }
        },
        pathSingleSlash { complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, html)) },
        path(yamlName) {
          complete(HttpEntity(MediaType.textWithFixedCharset("yaml", HttpCharsets.`UTF-8`), yaml))
        }
      )
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy