Skip to content

Commit

Permalink
feat: swagger & OpenAPI docs endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro committed Feb 8, 2024
1 parent 19b86fb commit e6ed2f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ lazy val searchApi = project
Dependencies.ciris ++
Dependencies.http4sDsl ++
Dependencies.http4sServer ++
Dependencies.tapirHttp4sServer
Dependencies.tapirHttp4sServer ++
Dependencies.tapirOpenAPi
)
.dependsOn(
commons % "compile->compile;test->test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.http4s.{HttpApp, HttpRoutes, Response}
import sttp.tapir.*
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.http4s.Http4sServerInterpreter
import sttp.tapir.swagger.bundle.SwaggerInterpreter

object HttpApplication:
def apply[F[_]: Async: Network](
Expand All @@ -45,7 +46,7 @@ class HttpApplication[F[_]: Async](searchApi: SearchApi[F])
Router[F]("/" -> routes).orNotFound

private lazy val routes: HttpRoutes[F] =
Http4sServerInterpreter[F]().toRoutes(endpoints)
Http4sServerInterpreter[F]().toRoutes(endpoints ::: swaggerEndpoints)

private lazy val endpoints: List[ServerEndpoint[Any, F]] =
List(
Expand All @@ -60,8 +61,13 @@ class HttpApplication[F[_]: Async](searchApi: SearchApi[F])
.in("api" / query)
.errorOut(borerJsonBody[String])
.out(borerJsonBody[List[Project]])
.description("Search API for searching Renku entities")

private lazy val pingEndpoint: PublicEndpoint[Unit, Unit, String, Any] =
endpoint.get
.in("ping")
.out(stringBody)
.description("Ping")

private lazy val swaggerEndpoints =
SwaggerInterpreter().fromServerEndpoints[F](endpoints, "Search API", "0.0.1")
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ object Dependencies {
val tapirHttp4sServer = Seq(
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % V.tapir
)
val tapirOpenAPi = Seq(
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % V.tapir
)
}

0 comments on commit e6ed2f5

Please sign in to comment.