From 8b61f9c7e940571d8e4a4e9494bae91a6b122fe9 Mon Sep 17 00:00:00 2001 From: Lintterer Date: Tue, 16 Jan 2024 15:29:35 +0100 Subject: [PATCH] chore: update scala 2.13 to 3.3.1 --- build.sbt | 6 +- project/Dependencies.scala | 2 +- project/build.properties | 2 +- .../smithy4play/SmithyPlayRouter.scala | 8 +- .../middleware/MiddlewareBase.scala | 2 +- .../middleware/ValidateAuthMiddleware.scala | 5 +- .../de/innfactory/smithy4play/package.scala | 156 +++++++++--------- 7 files changed, 90 insertions(+), 91 deletions(-) diff --git a/build.sbt b/build.sbt index 2903e33b..51ecf4c5 100644 --- a/build.sbt +++ b/build.sbt @@ -21,10 +21,10 @@ val githubSettings = Seq( ) ) -scalaVersion := "2.13.12" +scalaVersion := "3.3.1" val defaultProjectSettings = Seq( - scalaVersion := "2.13.12", + scalaVersion := "3.3.1", organization := "de.innfactory", version := releaseVersion ) ++ githubSettings @@ -41,7 +41,7 @@ lazy val smithy4play = project Compile / smithy4sInputDirs := Seq( (ThisBuild / baseDirectory).value / "smithy4play" / "src" / "resources" / "META_INF" / "smithy" ), - Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4play" / "target" / "scala-2.13" / "src_managed" / "main", + Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4play" / "target" / "scala-3.3.1" / "src_managed" / "main", name := "smithy4play", scalacOptions += "-Ymacro-annotations", Compile / compile / wartremoverWarnings ++= Warts.unsafe, diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 72fb0fe3..5472e039 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -6,7 +6,7 @@ object Dependencies { val playVersion = "3.0.1" val typesafePlay = "org.playframework" %% "play" % playVersion - val scalaVersion = "2.13.12" + val scalaVersion = "3.3.1" val smithy4sVersion = "0.17.19" val smithyCore = "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion val smithyJson = "com.disneystreaming.smithy4s" %% "smithy4s-json" % smithy4sVersion diff --git a/project/build.properties b/project/build.properties index fbf0bfc7..ae537384 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1,2 +1,2 @@ sbt.version = 1.9.8 -scala.version = 2.13.2 +scala.version = 3.3.1 diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayRouter.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayRouter.scala index 2a785540..03b5bdd4 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayRouter.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/SmithyPlayRouter.scala @@ -1,14 +1,14 @@ package de.innfactory.smithy4play -import cats.data.{ EitherT, Kleisli } +import cats.data.{EitherT, Kleisli} import cats.implicits.toTraverseOps import de.innfactory.smithy4play.middleware.MiddlewareBase -import play.api.mvc.{ AbstractController, ControllerComponents, Handler, RequestHeader } +import play.api.mvc.{AbstractController, ControllerComponents, Handler, RequestHeader} import play.api.routing.Router.Routes import smithy4s.HintMask -import smithy4s.http.{ HttpEndpoint, PathSegment } +import smithy4s.http.{HttpEndpoint, PathSegment} import smithy4s.internals.InputOutput -import smithy4s.kinds.{ FunctorAlgebra, Kind1, PolyFunction5 } +import smithy4s.kinds.{FunctorAlgebra, Kind1, PolyFunction5} import scala.concurrent.ExecutionContext diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/MiddlewareBase.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/MiddlewareBase.scala index 57441b7f..8aadf627 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/MiddlewareBase.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/MiddlewareBase.scala @@ -1,7 +1,7 @@ package de.innfactory.smithy4play.middleware import cats.data.Kleisli -import de.innfactory.smithy4play.{ EndpointResult, RouteResult, RoutingContext } +import de.innfactory.smithy4play.{RouteResult, RoutingContext} import play.api.Logger trait MiddlewareBase { diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/ValidateAuthMiddleware.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/ValidateAuthMiddleware.scala index b95f6802..5edd1ec9 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/ValidateAuthMiddleware.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/middleware/ValidateAuthMiddleware.scala @@ -7,14 +7,15 @@ import smithy.api.{ Auth, HttpBearerAuth } import javax.inject.{ Inject, Singleton } import scala.concurrent.{ ExecutionContext, Future } - +import smithy.api.AuthTraitReference.asBijection @Singleton class ValidateAuthMiddleware @Inject() (implicit executionContext: ExecutionContext ) extends MiddlewareBase { override protected def skipMiddleware(r: RoutingContext): Boolean = { - val serviceAuthHints = r.serviceHints.get(HttpBearerAuth.tagInstance).map(_ => Auth(Set(HttpBearerAuth.id.show))) + val serviceAuthHints = + r.serviceHints.get(HttpBearerAuth.tagInstance).flatMap(x => HttpBearerAuth.hints.get(Auth.tag)) for { authSet <- r.endpointHints.get(Auth.tag) orElse serviceAuthHints _ <- authSet.value.find(_.value == HttpBearerAuth.id.show) diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/package.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/package.scala index 99c6eb7a..7b4b84fb 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/package.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/package.scala @@ -1,104 +1,102 @@ -package de.innfactory +package de.innfactory.smithy4play -import cats.data.{ EitherT, Kleisli } -import de.innfactory.smithy4play.client.{ SmithyPlayClientEndpointErrorResponse, SmithyPlayClientEndpointResponse } +import cats.data.{EitherT, Kleisli} +import de.innfactory.smithy4play.client.SmithyPlayClientEndpointErrorResponse import org.slf4j import play.api.Logger -import play.api.libs.json.{ JsValue, Json } -import play.api.mvc.{ Headers, RequestHeader } -import smithy4s.http.{ CaseInsensitive, HttpEndpoint } +import play.api.libs.json.{JsValue, Json, OFormat} +import play.api.mvc.{Headers, RequestHeader} +import smithy4s.http.{CaseInsensitive, HttpEndpoint} -import scala.annotation.{ compileTimeOnly, StaticAnnotation } +import scala.annotation.{StaticAnnotation, compileTimeOnly} import scala.concurrent.Future import scala.language.experimental.macros -package object smithy4play { - - trait ContextRouteError extends StatusResult[ContextRouteError] { - def message: String - def toJson: JsValue - } +trait ContextRouteError extends StatusResult[ContextRouteError] { + def message: String + def toJson: JsValue +} - type ClientResponse[O] = Future[Either[SmithyPlayClientEndpointErrorResponse, SmithyPlayClientEndpointResponse[O]]] - type RunnableClientRequest[O] = Kleisli[ClientResponse, Option[Map[String, Seq[String]]], O] - type RouteResult[O] = EitherT[Future, ContextRouteError, O] - type ContextRoute[O] = Kleisli[RouteResult, RoutingContext, O] +type ClientResponse[O] = Future[ + Either[SmithyPlayClientEndpointErrorResponse, SmithyPlayClientEndpointResponse[O]] +] +type RunnableClientRequest[O] = Kleisli[ClientResponse, Option[Map[String, Seq[String]]], O] +type RouteResult[O] = EitherT[Future, ContextRouteError, O] +type ContextRoute[O] = Kleisli[RouteResult, RoutingContext, O] - trait StatusResult[S <: StatusResult[S]] { - def status: Status - def addHeaders(headers: Map[String, String]): S - } +trait StatusResult[S <: StatusResult[S]] { + def status: Status + def addHeaders(headers: Map[String, String]): S +} - case class Status(headers: Map[String, String], statusCode: Int) - object Status { - implicit val format = Json.format[Status] - } +case class Status(headers: Map[String, String], statusCode: Int) +object Status { + implicit val format: OFormat[Status] = Json.format[Status] +} - case class EndpointResult(body: Option[Array[Byte]], status: Status) extends StatusResult[EndpointResult] { - override def addHeaders(headers: Map[String, String]): EndpointResult = this.copy( - status = status.copy( - headers = status.headers ++ headers - ) +case class EndpointResult(body: Option[Array[Byte]], status: Status) extends StatusResult[EndpointResult] { + override def addHeaders(headers: Map[String, String]): EndpointResult = this.copy( + status = status.copy( + headers = status.headers ++ headers ) - } + ) +} - private[smithy4play] case class Smithy4PlayError( - message: String, - status: Status, - additionalInformation: Option[String] = None - ) extends ContextRouteError { - override def toJson: JsValue = Json.toJson(this)(Smithy4PlayError.format) - override def addHeaders(headers: Map[String, String]): Smithy4PlayError = this.copy( - status = status.copy( - headers = status.headers ++ headers - ) +private[smithy4play] case class Smithy4PlayError( + message: String, + status: Status, + additionalInformation: Option[String] = None +) extends ContextRouteError { + override def toJson: JsValue = Json.toJson(this)(Smithy4PlayError.format) + override def addHeaders(headers: Map[String, String]): Smithy4PlayError = this.copy( + status = status.copy( + headers = status.headers ++ headers ) - } - - object Smithy4PlayError { - implicit val format = Json.format[Smithy4PlayError] - } - - private[smithy4play] val logger: slf4j.Logger = Logger("smithy4play").logger + ) +} - private[smithy4play] def getHeaders(headers: Headers): Map[CaseInsensitive, Seq[String]] = - headers.headers.groupBy(_._1).map { case (k, v) => - (CaseInsensitive(k), v.map(_._2)) - } +object Smithy4PlayError { + implicit val format: OFormat[Smithy4PlayError] = Json.format[Smithy4PlayError] +} - private[smithy4play] def matchRequestPath( - x: RequestHeader, - ep: HttpEndpoint[_] - ): Option[Map[String, String]] = - ep.matches(x.path.replaceFirst("/", "").split("/").filter(_.nonEmpty)) +private[smithy4play] val logger: slf4j.Logger = Logger("smithy4play").logger - @compileTimeOnly( - "Macro failed to expand. \"Add: scalacOptions += \"-Ymacro-annotations\"\" to project settings" - ) - class AutoRouting extends StaticAnnotation { - def macroTransform(annottees: Any*): Any = macro AutoRoutingMacro.impl +private[smithy4play] def getHeaders(headers: Headers): Map[CaseInsensitive, Seq[String]] = + headers.headers.groupBy(_._1).map { case (k, v) => + (CaseInsensitive(k), v.map(_._2)) } - private[smithy4play] trait Showable { - this: Product => - override def toString: String = this.show - } +private[smithy4play] def matchRequestPath( + x: RequestHeader, + ep: HttpEndpoint[_] +): Option[Map[String, String]] = + ep.matches(x.path.replaceFirst("/", "").split("/").filter(_.nonEmpty)) + +@compileTimeOnly( + "Macro failed to expand. \"Add: scalacOptions += \"-Ymacro-annotations\"\" to project settings" +) +class AutoRouting extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro AutoRoutingMacro.impl +} - private[smithy4play] object Showable { - implicit class ShowableProduct(product: Product) { - def show: String = { - val className = product.productPrefix - val fieldNames = product.productElementNames.toList - val fieldValues = product.productIterator.toList - val fields = fieldNames.zip(fieldValues).map { case (name, value) => - value match { - case subProduct: Product => s"$name = ${subProduct.show}" - case _ => s"$name = $value" - } +private[smithy4play] trait Showable { + this: Product => + override def toString: String = this.show +} + +private[smithy4play] object Showable { + implicit class ShowableProduct(product: Product) { + def show: String = { + val className = product.productPrefix + val fieldNames = product.productElementNames.toList + val fieldValues = product.productIterator.toList + val fields = fieldNames.zip(fieldValues).map { case (name, value) => + value match { + case subProduct: Product => s"$name = ${subProduct.show}" + case _ => s"$name = $value" } - fields.mkString(s"$className(", ", ", ")") } + fields.mkString(s"$className(", ", ", ")") } } - }