Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update play and play test #236

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 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.3")

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 @@ -21,30 +24,28 @@ val githubSettings = Seq(
)
)

scalaVersion := "2.13.13"
scalaVersion := "3.3.1"

val defaultProjectSettings = Seq(
scalaVersion := "2.13.13",
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-2.13" / "src_managed" / "main",
Compile / smithy4sOutputDir := (Compile / sourceManaged).value / "main",
name := "smithy4play",
scalacOptions += "-Ymacro-annotations",
Compile / compile / wartremoverWarnings ++= Warts.unsafe,
libraryDependencies ++= Dependencies.list
)

Expand All @@ -55,8 +56,6 @@ lazy val smithy4playTest = project
sharedSettings,
scalaVersion := Dependencies.scalaVersion,
name := "smithy4playTest",
scalacOptions += "-Ymacro-annotations",
Compile / compile / wartremoverWarnings ++= Warts.unsafe,
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
20 changes: 10 additions & 10 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ 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 = "2.13.13"
val smithy4sVersion = "0.18.15"
val scalaVersion = "3.3.1"
val smithy4sVersion = "0.18.23"
val smithyCore = "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion
val smithyJson = "com.disneystreaming.smithy4s" %% "smithy4s-json" % smithy4sVersion
val smithyXml = "com.disneystreaming.smithy4s" %% "smithy4s-xml" % smithy4sVersion
val smithy4sCompliance = "com.disneystreaming.smithy4s" %% "smithy4s-compliance-tests" % smithy4sVersion
val alloyCore = "com.disneystreaming.alloy" % "alloy-core" % "0.3.6"
val alloyOpenapi = "com.disneystreaming.alloy" %% "alloy-openapi" % "0.3.6"
val alloyCore = "com.disneystreaming.alloy" % "alloy-core" % "0.3.11"
val alloyOpenapi = "com.disneystreaming.alloy" %% "alloy-openapi" % "0.3.11"

val classgraph = "io.github.classgraph" % "classgraph" % "4.8.168"
val smithyVersion = "1.45.0"
val classgraph = "io.github.classgraph" % "classgraph" % "4.8.174"
val smithyVersion = "1.50.0"
val testTraits =
"software.amazon.smithy" % "smithy-protocol-test-traits" % smithyVersion

val scalatestPlus =
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test
val cats = "org.typelevel" %% "cats-core" % "2.9.0"
"org.scalatestplus.play" %% "scalatestplus-play" % "7.0.1" % Test
val cats = "org.typelevel" %% "cats-core" % "2.12.0"

lazy val list = Seq(
smithyCore,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sbt.version = 1.9.8
scala.version = 2.13.2
scala.version = 3.3.1
5 changes: 2 additions & 3 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("com.disneystreaming.smithy4s" %% "smithy4s-sbt-codegen" % "0.18.23")
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 @@ -4,23 +4,25 @@ import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig
import de.innfactory.smithy4play.middleware.MiddlewareBase
import play.api.mvc.ControllerComponents
import play.api.routing.Router.Routes
import smithy4s.json.JsoniterCodecCompiler
import smithy4s.kinds.FunctorAlgebra

import scala.concurrent.ExecutionContext

trait AutoRoutableController {
type Router = (Seq[MiddlewareBase], ReaderConfig, JsoniterCodecCompiler) => Routes

implicit def transformToRouter[Alg[_[_, _, _, _, _]], F[
_
] <: ContextRoute[_]](
implicit def transformToRouter[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[?]](
impl: FunctorAlgebra[Alg, F]
)(implicit
service: smithy4s.Service[Alg],
ec: ExecutionContext,
cc: ControllerComponents
): (Seq[MiddlewareBase], ReaderConfig) => Routes = (middlewares: Seq[MiddlewareBase], readerConfig: ReaderConfig) =>
new SmithyPlayRouter[Alg, F](impl, service).routes(middlewares, readerConfig)
): Router =
(middlewares: Seq[MiddlewareBase], readerConfig: ReaderConfig, jsoniterCodecCompiler: JsoniterCodecCompiler) =>
new SmithyPlayRouter[Alg, F](impl, service)
.routes(middlewares, readerConfig, jsoniterCodecCompiler)

val router: (Seq[MiddlewareBase], ReaderConfig) => Routes
val router: Router

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import io.github.classgraph.{ ClassGraph, ScanResult }
import play.api.Application
import play.api.mvc.ControllerComponents
import play.api.routing.Router.Routes
import smithy4s.json.Json

import java.util.Optional
import javax.inject.{ Inject, Provider, Singleton }
import javax.inject.{ Inject, Singleton }
import scala.concurrent.ExecutionContext
import scala.jdk.CollectionConverters.CollectionHasAsScala
import scala.util.Try
Expand All @@ -23,8 +23,9 @@ class AutoRouter @Inject(
config: Config
) extends BaseRouter {

private val pkg = config.getString("smithy4play.autoRoutePackage")
private val readerConfig = ReaderConfig.fromApplicationConfig(config)
private val pkg = config.getString("smithy4play.autoRoutePackage")
private val readerConfig = ReaderConfig.fromApplicationConfig(config)
private val jsoniterCodecCompiler = Json.jsoniter.fromApplicationConfig(config)

override val controllers: Seq[Routes] = {
val classGraphScanner: ScanResult = new ClassGraph().enableAllInfo().acceptPackages(pkg).scan()
Expand All @@ -34,14 +35,18 @@ class AutoRouter @Inject(
}.toOption.getOrElse(Seq(validateAuthMiddleware))
logger.debug(s"[AutoRouter] found ${controllers.size().toString} controllers")
logger.debug(s"[AutoRouter] found ${middlewares.size.toString} middlewares")
val routes = controllers.asScala.map(_.loadClass(true)).map(clazz => createFromClass(clazz, middlewares)).toSeq
val routes = controllers.asScala
.filter(!_.isAbstract)
.map(_.loadClass(true))
.map(clazz => createFromClass(clazz, middlewares))
.toSeq
classGraphScanner.close()
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)
case c: AutoRoutableController => c.router(middlewares, readerConfig, jsoniterCodecCompiler)
}

}

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 @@ -2,22 +2,23 @@ package de.innfactory.smithy4play

import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig
import play.api.http.MimeTypes
import smithy4s.capability.instances.either._
import smithy4s.capability.instances.either.*
import smithy4s.codecs.Writer.CachedCompiler
import smithy4s.codecs._
import smithy4s.codecs.*
import smithy4s.http.{ HttpResponse, HttpRestSchema, Metadata, MetadataError }
import smithy4s.json.Json
import smithy4s.json.{ Json, JsoniterCodecCompiler }
import smithy4s.kinds.PolyFunction
import smithy4s.schema.CachedSchemaCompiler
import smithy4s.xml.Xml
import smithy4s.{ codecs, Blob }

case class CodecDecider(readerConfig: ReaderConfig) {
case class CodecDecider(
readerConfig: ReaderConfig,
jsoniterCodecCompiler: JsoniterCodecCompiler
) {

private val jsonCodecs = Json.payloadCodecs
.withJsoniterCodecCompiler(
Json.jsoniter
)
.withJsoniterCodecCompiler(jsoniterCodecCompiler)
.withJsoniterReaderConfig(readerConfig)

private val jsonEncoder: BlobEncoder.Compiler = jsonCodecs.encoders
Expand All @@ -28,7 +29,7 @@ case class CodecDecider(readerConfig: ReaderConfig) {
def encoder(
contentType: Seq[String]
): CachedSchemaCompiler[codecs.BlobEncoder] =
contentType match {
contentType.map(_.split(";").head) match {
case Seq(MimeTypes.JSON) => jsonEncoder
case Seq(MimeTypes.XML) => Xml.encoders
case _ =>
Expand All @@ -38,18 +39,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 +69,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 +109,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,15 +122,15 @@ 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(
contentType: Seq[String]
): CachedSchemaCompiler[BlobDecoder] =
contentType match {
contentType.map(_.split(";").head) match {
case Seq(MimeTypes.JSON) => jsonDecoder
case Seq(MimeTypes.XML) => Xml.decoders
case _ =>
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
Loading
Loading