From 934fbb1284224a5a784492ef2f1dbef7f03bac71 Mon Sep 17 00:00:00 2001 From: Lintterer Date: Mon, 29 Apr 2024 14:20:12 +0200 Subject: [PATCH] chore: scalafmt --- .../innfactory/smithy4play/CodecDecider.scala | 6 +- .../smithy4play/SmithyPlayEndpoint.scala | 78 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/CodecDecider.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/CodecDecider.scala index 93a0e044..9b2415ee 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/CodecDecider.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/CodecDecider.scala @@ -5,12 +5,12 @@ import play.api.http.MimeTypes import smithy4s.capability.instances.either._ import smithy4s.codecs.Writer.CachedCompiler import smithy4s.codecs._ -import smithy4s.http.{HttpResponse, HttpRestSchema, Metadata, MetadataError} +import smithy4s.http.{ HttpResponse, HttpRestSchema, Metadata, MetadataError } import smithy4s.json.Json import smithy4s.kinds.PolyFunction -import smithy4s.schema.{CachedSchemaCompiler, Schema} +import smithy4s.schema.{ CachedSchemaCompiler, Schema } import smithy4s.xml.Xml -import smithy4s.{Blob, PartialData, codecs} +import smithy4s.{ codecs, Blob, PartialData } case class CodecDecider(readerConfig: ReaderConfig) { diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayEndpoint.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayEndpoint.scala index ca88e37b..8cd6f66b 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayEndpoint.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayEndpoint.scala @@ -14,13 +14,13 @@ import javax.inject.Inject import scala.concurrent.{ ExecutionContext, Future } class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _, _, _, _], I, E, O, SI, SO]( - service: Service[Alg], - impl: FunctorInterpreter[Op, F], - middleware: Seq[MiddlewareBase], - endpoint: Endpoint[Op, I, E, O, SI, SO], - codecDecider: CodecDecider - )(implicit cc: ControllerComponents, ec: ExecutionContext) - extends AbstractController(cc) { + service: Service[Alg], + impl: FunctorInterpreter[Op, F], + middleware: Seq[MiddlewareBase], + endpoint: Endpoint[Op, I, E, O, SI, SO], + codecDecider: CodecDecider +)(implicit cc: ControllerComponents, ec: ExecutionContext) + extends AbstractController(cc) { private val httpEndpoint: Either[HttpEndpoint.HttpEndpointError, HttpEndpoint[I]] = HttpEndpoint.cast(endpoint.schema) private val serviceHints = service.hints @@ -33,38 +33,38 @@ class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _ Metadata.Encoder.fromSchema(outputSchema) def handler(v1: RequestHeader): Handler = httpEndpoint.map { httpEp => - Action.async(parse.raw) { implicit request => - if (request.body.size > 0 && request.body.asBytes().isEmpty) { - logger.error( - "received body size does not equal the parsed body size. \n" + - "This is probably due to the body being too large and thus play is unable to parse.\n" + - "Try setting play.http.parser.maxMemoryBuffer in application.conf" - ) - } + Action.async(parse.raw) { implicit request => + if (request.body.size > 0 && request.body.asBytes().isEmpty) { + logger.error( + "received body size does not equal the parsed body size. \n" + + "This is probably due to the body being too large and thus play is unable to parse.\n" + + "Try setting play.http.parser.maxMemoryBuffer in application.conf" + ) + } - implicit val epContentType: ContentType = ContentType(request.contentType.getOrElse(serviceContentType)) - val result = for { - pathParams <- getPathParams(v1, httpEp) - metadata = getMetadata(pathParams, v1) - input <- getInput(request, metadata) - endpointLogic = impl(endpoint.wrap(input)) - .asInstanceOf[Kleisli[RouteResult, RoutingContext, O]] - .map(mapToEndpointResult(httpEp.code)) - chainedMiddlewares = middleware.foldRight(endpointLogic)((a, b) => a.middleware(b.run)) - res <- - chainedMiddlewares.run(RoutingContext.fromRequest(request, serviceHints, endpointHints, v1)) - } yield res - result.value.map { - case Left(value) => handleFailure(value) - case Right(value) => handleSuccess(value) - } + implicit val epContentType: ContentType = ContentType(request.contentType.getOrElse(serviceContentType)) + val result = for { + pathParams <- getPathParams(v1, httpEp) + metadata = getMetadata(pathParams, v1) + input <- getInput(request, metadata) + endpointLogic = impl(endpoint.wrap(input)) + .asInstanceOf[Kleisli[RouteResult, RoutingContext, O]] + .map(mapToEndpointResult(httpEp.code)) + chainedMiddlewares = middleware.foldRight(endpointLogic)((a, b) => a.middleware(b.run)) + res <- + chainedMiddlewares.run(RoutingContext.fromRequest(request, serviceHints, endpointHints, v1)) + } yield res + result.value.map { + case Left(value) => handleFailure(value) + case Right(value) => handleSuccess(value) } } + } .getOrElse(Action(NotFound("404"))) private def mapToEndpointResult( - statusCode: Int - )(output: O): HttpResponse[Blob] = { + statusCode: Int + )(output: O): HttpResponse[Blob] = { val outputMetadata = outputMetadataEncoder.encode(output).headers.get(CaseInsensitive("content-type")) match { case Some(value) => value case None => Seq(serviceContentType) @@ -83,9 +83,9 @@ class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _ } private def getPathParams( - v1: RequestHeader, - httpEp: HttpEndpoint[I] - )(implicit defaultContentType: ContentType): EitherT[Future, ContextRouteError, Map[String, String]] = + v1: RequestHeader, + httpEp: HttpEndpoint[I] + )(implicit defaultContentType: ContentType): EitherT[Future, ContextRouteError, Map[String, String]] = EitherT( Future( matchRequestPath(v1, httpEp) @@ -100,9 +100,9 @@ class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _ ) private def getInput( - request: Request[RawBuffer], - metadata: Metadata - )(implicit defaultContentType: ContentType): EitherT[Future, ContextRouteError, I] = + request: Request[RawBuffer], + metadata: Metadata + )(implicit defaultContentType: ContentType): EitherT[Future, ContextRouteError, I] = EitherT { Future { val codec = codecDecider.requestDecoder(Seq(defaultContentType.value))