Skip to content

Commit

Permalink
feat: upgrade to smithy4s 0.18.15
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNico committed Apr 17, 2024
1 parent b057d8c commit 23c9f2b
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 99 deletions.
20 changes: 10 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sbt.Compile
import sbt.Keys.cleanFiles
val releaseVersion = sys.env.getOrElse("TAG", "1.0.1-Gamma")

val releaseVersion = sys.env.getOrElse("TAG", "1.1.0-Three.1")

addCommandAlias("publishSmithy4Play", "smithy4play/publish")
addCommandAlias("publishLocalSmithy4Play", "smithy4play/publishLocal")
addCommandAlias("generateCoverage", "clean; coverage; test; coverageReport")

val token = sys.env.getOrElse("GITHUB_TOKEN", "")
val githubSettings = Seq(
githubOwner := "innFactory",
Expand All @@ -23,28 +26,26 @@ val githubSettings = Seq(

scalaVersion := "3.3.1"

val defaultProjectSettings = Seq(
val sharedSettings = Seq(
scalaVersion := "3.3.1",
scalacOptions ++= Seq("-Ykind-projector:underscores"),
organization := "de.innfactory",
version := releaseVersion
) ++ githubSettings

val sharedSettings = defaultProjectSettings

lazy val smithy4play = project
.in(file("smithy4play"))
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
sharedSettings,
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.3" cross CrossVersion.full),
// addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.3" cross CrossVersion.full),
scalaVersion := Dependencies.scalaVersion,
Compile / smithy4sAllowedNamespaces := List("smithy.smithy4play", "aws.protocols"),
Compile / smithy4sInputDirs := Seq(
(ThisBuild / baseDirectory).value / "smithy4play" / "src" / "resources" / "META_INF" / "smithy"
),
Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4play" / "target" / "scala-3.3.1" / "src_managed" / "main",
Compile / smithy4sOutputDir := (Compile / sourceManaged).value / "main",
name := "smithy4play",
Compile / compile / wartremoverWarnings ++= Warts.unsafe,
libraryDependencies ++= Dependencies.list
)

Expand All @@ -53,9 +54,8 @@ lazy val smithy4playTest = project
.enablePlugins(Smithy4sCodegenPlugin, PlayScala)
.settings(
sharedSettings,
scalaVersion := Dependencies.scalaVersion,
name := "smithy4playTest",
Compile / compile / wartremoverWarnings ++= Warts.unsafe,
scalaVersion := Dependencies.scalaVersion,
name := "smithy4playTest",
cleanKeepFiles += (ThisBuild / baseDirectory).value / "smithy4playTest" / "app",
cleanFiles += (ThisBuild / baseDirectory).value / "smithy4playTest" / "app" / "specs" / "testDefinitions" / "test",
Compile / smithy4sInputDirs := Seq((ThisBuild / baseDirectory).value / "smithy4playTest" / "testSpecs"),
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import sbt._

object Dependencies {

val playVersion = "2.9.2"
val typesafePlay = "com.typesafe.play" %% "play" % playVersion
val playVersion = "3.0.1"
val typesafePlay = "org.playframework" %% "play" % playVersion

val scalaVersion = "3.3.1"
val smithy4sVersion = "0.18.15"
Expand Down
3 changes: 1 addition & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
addSbtPlugin("com.codecommit" %% "sbt-github-packages" % "0.5.3")
addSbtPlugin("org.wartremover" %% "sbt-wartremover" % "3.1.6")
addSbtPlugin("org.scalameta" %% "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.disneystreaming.smithy4s" %% "smithy4s-sbt-codegen" % "0.18.15")
addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.9.2")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1")
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "2.0.11")

ThisBuild / dependencyOverrides ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.concurrent.ExecutionContext

trait AutoRoutableController {

implicit def transformToRouter[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_]](
implicit def transformToRouter[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[?]](
impl: FunctorAlgebra[Alg, F]
)(implicit
service: smithy4s.Service[Alg],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AutoRouter @Inject(
routes
}

private def createFromClass(clazz: Class[_], middlewares: Seq[MiddlewareBase]): Routes =
private def createFromClass(clazz: Class[?], middlewares: Seq[MiddlewareBase]): Routes =
app.injector.instanceOf(clazz) match {
case c: AutoRoutableController => c.router(middlewares, readerConfig)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class BaseRouter(implicit

implicit def transformToRouter[Alg[_[_, _, _, _, _]], F[
_
] <: ContextRoute[_]](
] <: ContextRoute[?]](
impl: FunctorAlgebra[Alg, F]
)(implicit
serviceProvider: smithy4s.Service[Alg],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ case class CodecDecider(readerConfig: ReaderConfig) {

def requestDecoder(
contentType: Seq[String]
): CachedSchemaCompiler[Decoder[Either[Throwable, *], PlayHttpRequest[Blob], *]] =
HttpRestSchema.combineDecoderCompilers[Either[Throwable, *], PlayHttpRequest[Blob]](
): CachedSchemaCompiler[Decoder[Either[Throwable, _], PlayHttpRequest[Blob], _]] =
HttpRestSchema.combineDecoderCompilers[Either[Throwable, _], PlayHttpRequest[Blob]](
metadataDecoder
.mapK(
Decoder.in[Either[MetadataError, *]].composeK[Metadata, PlayHttpRequest[Blob]](_.metadata)
Decoder.in[Either[MetadataError, _]].composeK[Metadata, PlayHttpRequest[Blob]](_.metadata)
)
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, *], PlayHttpRequest[Blob], *]]],
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, _], PlayHttpRequest[Blob], _]]],
decoder(contentType)
.mapK(
Decoder.in[Either[PayloadError, *]].composeK[Blob, PlayHttpRequest[Blob]](_.body)
Decoder.in[Either[PayloadError, _]].composeK[Blob, PlayHttpRequest[Blob]](_.body)
)
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, *], PlayHttpRequest[Blob], *]]],
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, _], PlayHttpRequest[Blob], _]]],
_ => Right(())
)(eitherZipper)

Expand All @@ -68,22 +68,22 @@ case class CodecDecider(readerConfig: ReaderConfig) {

def httpResponseDecoder(
contentType: Seq[String]
): CachedSchemaCompiler[Decoder[Either[Throwable, *], HttpResponse[Blob], *]] =
HttpRestSchema.combineDecoderCompilers[Either[Throwable, *], HttpResponse[Blob]](
): CachedSchemaCompiler[Decoder[Either[Throwable, _], HttpResponse[Blob], _]] =
HttpRestSchema.combineDecoderCompilers[Either[Throwable, _], HttpResponse[Blob]](
metadataDecoder
.mapK(
Decoder
.in[Either[MetadataError, *]]
.in[Either[MetadataError, _]]
.composeK[Metadata, HttpResponse[Blob]](r =>
Metadata(Map.empty, Map.empty, headers = r.headers, statusCode = Some(r.statusCode))
)
)
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, *], HttpResponse[Blob], *]]],
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, _], HttpResponse[Blob], _]]],
decoder(contentType)
.mapK(
Decoder.in[Either[PayloadError, *]].composeK[Blob, HttpResponse[Blob]](_.body)
Decoder.in[Either[PayloadError, _]].composeK[Blob, HttpResponse[Blob]](_.body)
)
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, *], HttpResponse[Blob], *]]],
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, _], HttpResponse[Blob], _]]],
_ => Right(())
)(eitherZipper)

Expand All @@ -108,9 +108,9 @@ case class CodecDecider(readerConfig: ReaderConfig) {
(insensitive, value)
})
)
private val httpRequestBlobPipe: PolyFunction[Encoder[Blob, *], Writer[HttpResponse[Blob], *]] =
private val httpRequestBlobPipe: PolyFunction[Encoder[Blob, _], Writer[HttpResponse[Blob], _]] =
smithy4s.codecs.Encoder.pipeToWriterK[HttpResponse[Blob], Blob](httpRequestBodyLift)
private val httpRequestMetadataPipe: PolyFunction[Encoder[Metadata, *], Writer[HttpResponse[Blob], *]] =
private val httpRequestMetadataPipe: PolyFunction[Encoder[Metadata, _], Writer[HttpResponse[Blob], _]] =
smithy4s.codecs.Encoder.pipeToWriterK(httpRequestMetadataLift)

private val blobLift: Writer[EndpointRequest, Blob] =
Expand All @@ -121,9 +121,9 @@ case class CodecDecider(readerConfig: ReaderConfig) {
(insensitive, value)
})
)
private val blobPipe: PolyFunction[Encoder[Blob, *], Writer[EndpointRequest, *]] =
private val blobPipe: PolyFunction[Encoder[Blob, _], Writer[EndpointRequest, _]] =
smithy4s.codecs.Encoder.pipeToWriterK[EndpointRequest, Blob](blobLift)
private val metadataPipe: PolyFunction[Encoder[Metadata, *], Writer[EndpointRequest, *]] =
private val metadataPipe: PolyFunction[Encoder[Metadata, _], Writer[EndpointRequest, _]] =
smithy4s.codecs.Encoder.pipeToWriterK(metadataLift)

def decoder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ case class RoutingContext(
attributes: Map[String, Any],
requestHeader: RequestHeader
) {
def hasHints(s: ShapeTag.Companion[_]): Boolean = hasEndpointHints(s) || hasServiceHints(s)
def hasServiceHints(s: ShapeTag.Companion[_]): Boolean = serviceHints.has(s.tagInstance)
def hasEndpointHints(s: ShapeTag.Companion[_]): Boolean = endpointHints.has(s.tagInstance)
def hasHints(s: ShapeTag.Companion[?]): Boolean = hasEndpointHints(s) || hasServiceHints(s)
def hasServiceHints(s: ShapeTag.Companion[?]): Boolean = serviceHints.has(s.tagInstance)
def hasEndpointHints(s: ShapeTag.Companion[?]): Boolean = endpointHints.has(s.tagInstance)
}

object RoutingContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import smithy4s.{ Blob, Endpoint, Service }
import javax.inject.Inject
import scala.concurrent.{ ExecutionContext, Future }

class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _, _, _, _], I, E, O, SI, SO](
class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[?], Op[_, _, _, _, _], I, E, O, SI, SO](
service: Service[Alg],
impl: FunctorInterpreter[Op, F],
middleware: Seq[MiddlewareBase],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import smithy4s.xml.Xml

import scala.concurrent.ExecutionContext

class SmithyPlayRouter[Alg[_[_, _, _, _, _]], F[
_
] <: ContextRoute[_]](
class SmithyPlayRouter[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[?]](
impl: FunctorAlgebra[Alg, F],
service: smithy4s.Service[Alg]
)(implicit cc: ControllerComponents, ec: ExecutionContext)
Expand All @@ -26,8 +24,8 @@ class SmithyPlayRouter[Alg[_[_, _, _, _, _]], F[
def routes(middlewares: Seq[MiddlewareBase], readerConfig: ReaderConfig): Routes = {

val interpreter: PolyFunction5[service.Operation, Kind1[F]#toKind5] = service.toPolyFunction[Kind1[F]#toKind5](impl)
val endpoints: Seq[service.Endpoint[_, _, _, _, _]] = service.endpoints
val httpEndpoints: Seq[Either[HttpEndpoint.HttpEndpointError, HttpEndpoint[_]]] =
val endpoints: Seq[service.Endpoint[?, ?, ?, ?, ?]] = service.endpoints
val httpEndpoints: Seq[Either[HttpEndpoint.HttpEndpointError, HttpEndpoint[?]]] =
endpoints.map(ep => HttpEndpoint.cast(ep.schema))
val codecDecider = CodecDecider(readerConfig)

Expand Down Expand Up @@ -64,7 +62,7 @@ class SmithyPlayRouter[Alg[_[_, _, _, _, _]], F[

private def checkIfRequestHeaderMatchesEndpoint(
x: RequestHeader,
ep: HttpEndpoint[_]
ep: HttpEndpoint[?]
): Boolean = {
ep.path.map {
case PathSegment.StaticSegment(value) => value
Expand Down
14 changes: 3 additions & 11 deletions smithy4play/src/main/scala/de/innfactory/smithy4play/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import play.api.Logger
import play.api.http.MimeTypes
import play.api.libs.json.{ JsValue, Json, OFormat }
import play.api.mvc.{ Headers, RequestHeader }
import smithy4s.{ Blob, Hints }
import smithy4s.http.{ CaseInsensitive, HttpEndpoint, HttpResponse, Metadata }
import smithy4s.{ Blob, Hints }

import scala.annotation.{ compileTimeOnly, StaticAnnotation }
import scala.concurrent.Future
import scala.language.experimental.macros
import scala.util.Try
Expand Down Expand Up @@ -133,7 +132,7 @@ package object smithy4play {
}

object Smithy4PlayError {
implicit val format = Json.format[Smithy4PlayError]
implicit val format: OFormat[Smithy4PlayError] = Json.format[Smithy4PlayError]
}

private[smithy4play] val logger: slf4j.Logger = Logger("smithy4play").logger
Expand All @@ -145,17 +144,10 @@ package object smithy4play {

private[smithy4play] def matchRequestPath(
x: RequestHeader,
ep: HttpEndpoint[_]
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] trait Showable {
this: Product =>
override def toString: String = this.show
Expand Down
12 changes: 8 additions & 4 deletions smithy4playTest/app/controller/TestController.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package controller

import cats.data.{ EitherT, Kleisli }
import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig
import controller.models.TestError
import de.innfactory.smithy4play.{ AutoRouting, ContextRoute, ContextRouteError }
import de.innfactory.smithy4play.middleware.MiddlewareBase
import de.innfactory.smithy4play.{ AutoRoutableController, ContextRoute, ContextRouteError }
import play.api.mvc.ControllerComponents
import play.api.routing.Router.Routes
import smithy4s.Blob
import testDefinitions.test._
import testDefinitions.test.*

import javax.inject.{ Inject, Singleton }
import scala.concurrent.{ ExecutionContext, Future }

@Singleton
@AutoRouting
class TestController @Inject() (implicit
cc: ControllerComponents,
executionContext: ExecutionContext
) extends TestControllerService[ContextRoute] {
) extends TestControllerService[ContextRoute]
with AutoRoutableController {
override val router: (Seq[MiddlewareBase], ReaderConfig) => Routes = this

override def test(): ContextRoute[SimpleTestResponse] = Kleisli { rc =>
rc.attributes.get("Not") match {
Expand Down
10 changes: 7 additions & 3 deletions smithy4playTest/app/controller/XmlController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package controller

import cats.data.{ EitherT, Kleisli }
import cats.implicits.catsSyntaxEitherId
import de.innfactory.smithy4play.{ AutoRouting, ContextRoute, ContextRouteError }
import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig
import de.innfactory.smithy4play.middleware.MiddlewareBase
import de.innfactory.smithy4play.{ AutoRoutableController, ContextRoute, ContextRouteError }
import play.api.mvc.ControllerComponents
import play.api.routing.Router.Routes
import testDefinitions.test.{ XmlControllerDef, XmlTestInputBody, XmlTestOutput, XmlTestWithInputAndOutputOutput }

import javax.inject.{ Inject, Singleton }
import scala.concurrent.{ ExecutionContext, Future }

@Singleton
@AutoRouting
class XmlController @Inject() (implicit
cc: ControllerComponents,
executionContext: ExecutionContext
) extends XmlControllerDef[ContextRoute] {
) extends XmlControllerDef[ContextRoute]
with AutoRoutableController {
override val router: (Seq[MiddlewareBase], ReaderConfig) => Routes = this

override def xmlTestWithInputAndOutput(
xmlTest: String,
Expand Down
Loading

0 comments on commit 23c9f2b

Please sign in to comment.