Skip to content

Commit

Permalink
Bump tapir to 1.9.1
Browse files Browse the repository at this point in the history
This includes streaming files above threshold to disk to avoid ooms :^)
The value is customizable, but lets try the default first.
  • Loading branch information
jnatten committed Nov 21, 2023
1 parent 273e5c0 commit fb7eb10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions network/src/main/scala/no/ndla/network/tapir/Routes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import sttp.tapir.server.http4s.{Http4sServerInterpreter, Http4sServerOptions}
import sttp.tapir.server.interceptor.RequestInterceptor.RequestResultEffectTransform
import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler
import sttp.tapir.server.interceptor.exception.{ExceptionContext, ExceptionHandler}
import sttp.tapir.server.interceptor.reject.RejectHandler
import sttp.tapir.server.interceptor.reject.{RejectContext, RejectHandler}
import sttp.tapir.server.interceptor.{RequestInterceptor, RequestResult}
import sttp.tapir.server.jdkhttp.{Id, JdkHttpServer, JdkHttpServerOptions}
import sttp.tapir.server.model.ValuedEndpointOutput
Expand All @@ -52,8 +52,8 @@ trait Routes[F[_]] {
ValuedEndpointOutput(jsonBody[AllErrors], ErrorHelpers.generic)
}

private val decodeFailureHandler: DefaultDecodeFailureHandler =
DefaultDecodeFailureHandler.default
private def decodeFailureHandler[T[_]]: DefaultDecodeFailureHandler[T] =
DefaultDecodeFailureHandler[T]
.response(failureMsg => {
ValuedEndpointOutput(
jsonBody[AllErrors],
Expand All @@ -77,10 +77,9 @@ trait Routes[F[_]] {
}

case class NdlaRejectHandler[A[_]]() extends RejectHandler[A] {
override def apply(
failure: RequestResult.Failure
)(implicit monad: MonadError[A]): A[Option[ValuedEndpointOutput[_]]] = {
val statusCodeAndBody = if (hasMethodMismatch(failure)) {

override def apply(ctx: RejectContext)(implicit monad: MonadError[A]): A[Option[ValuedEndpointOutput[_]]] = {
val statusCodeAndBody = if (hasMethodMismatch(ctx.failure)) {
ValuedEndpointOutput(jsonBody[ErrorBody], ErrorHelpers.methodNotAllowed)
.prepend(statusCode, StatusCode.MethodNotAllowed)
} else {
Expand All @@ -89,7 +88,6 @@ trait Routes[F[_]] {
}
monad.unit(Some(statusCodeAndBody))
}

}

private def swaggerServicesToRoutes(services: List[Service[IO]]): HttpRoutes[IO] = {
Expand All @@ -99,7 +97,7 @@ trait Routes[F[_]] {
.defaultHandlers(err => failureResponse(err, None))
.rejectHandler(NdlaRejectHandler[IO]())
.exceptionHandler(NdlaExceptionHandler[IO]())
.decodeFailureHandler(decodeFailureHandler)
.decodeFailureHandler(decodeFailureHandler[IO])
.serverLog(None)
.options
Http4sServerInterpreter[IO](options).toRoutes(swaggerEndpoints)
Expand Down Expand Up @@ -186,7 +184,7 @@ trait Routes[F[_]] {
.defaultHandlers(err => failureResponse(err, None))
.rejectHandler(NdlaRejectHandler[Id]())
.exceptionHandler(NdlaExceptionHandler[Id]())
.decodeFailureHandler(decodeFailureHandler)
.decodeFailureHandler(decodeFailureHandler[Id])
.serverLog(None)
.prependInterceptor(RequestInterceptor.transformServerRequest[Id](JDKMiddleware.before))
.prependInterceptor(RequestInterceptor.transformResultEffect(new JDKMiddleware.after))
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object Dependencies {
val PostgresV = "42.5.1"
val ScalaTsiV = "0.6.0"
val Http4sV = "0.23.23"
val TapirV = "1.7.4"
val ApiSpecV = "0.6.0"
val TapirV = "1.9.1"
val ApiSpecV = "0.7.1"
val SttpV = "3.9.0"
val CirceV = "0.14.2"
val ScalikeJDBCV = "4.0.0"
Expand Down

0 comments on commit fb7eb10

Please sign in to comment.