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 smithy4s-compliance-tests, ... from 0.17.19 to 0.18.3 #217

Merged
merged 22 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
96da098
chore: update smithy4s-compliance-tests, ... from 0.17.19 to 0.18.3
jona7o Nov 4, 2023
cff801d
chore: update smithy4s-compliance-tests, ... from 0.17.19 to 0.18.3
jona7o Dec 21, 2023
8a2b523
feat: initial revamp to 18.3
MoeQuadrat Dec 22, 2023
aaa2a44
chore: merge
MoeQuadrat Dec 22, 2023
535d702
feat: set correct content type when sending json
MoeQuadrat Jan 15, 2024
7042031
refactor: using HttpResponse and HttpRequest
MoeQuadrat Jan 16, 2024
d9df4f8
fix: use correct codecs for server and client endpoints
MoeQuadrat Jan 18, 2024
a8413a9
chore: scalafmt
MoeQuadrat Jan 18, 2024
b5cf9c4
refactor: using codedecider to choose correct codec from contenttype
MoeQuadrat Jan 18, 2024
e521fe0
feat: initial revamp to composing decoder
MoeQuadrat Feb 1, 2024
309e944
feat: compose codecs for client
MoeQuadrat Feb 5, 2024
b8ec81a
chore: scalafmt
MoeQuadrat Feb 5, 2024
564c69e
chore: scalafmt
MoeQuadrat Feb 5, 2024
2896a79
refactor: remove imports and use correct encoder and decoder
MoeQuadrat Feb 5, 2024
292afce
chore: scalafmt
MoeQuadrat Feb 5, 2024
9c1c092
chore: scalafmt
MoeQuadrat Feb 5, 2024
0197601
feat: use input content-type as output content-type
MoeQuadrat Feb 7, 2024
6ad6ec1
refactor: rename smithy definitions to increase clearity
MoeQuadrat Feb 7, 2024
b77fcfc
test: add tests for xml protocol in default json controller
MoeQuadrat Feb 7, 2024
f9a6c4f
chore: scalafmt
MoeQuadrat Feb 7, 2024
7fa3871
chore: update smithy4s version
MoeQuadrat Feb 7, 2024
db36e45
fix: set empty structs to true
MoeQuadrat Feb 7, 2024
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
19 changes: 10 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sbt.Compile
import sbt.Keys.cleanFiles
val releaseVersion = sys.env.getOrElse("TAG", "0.4.4-Delta")
val releaseVersion = sys.env.getOrElse("TAG", "1.0.0-Gamma")
addCommandAlias("publishSmithy4Play", "smithy4play/publish")
addCommandAlias("publishLocalSmithy4Play", "smithy4play/publishLocal")
addCommandAlias("generateCoverage", "clean; coverage; test; coverageReport")
Expand Down Expand Up @@ -29,15 +29,15 @@ val defaultProjectSettings = Seq(
version := releaseVersion
) ++ githubSettings

val sharedSettings = defaultProjectSettings

val sharedSettings = defaultProjectSettings
lazy val smithy4play = project
.in(file("smithy4play"))
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
sharedSettings,
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full),
scalaVersion := Dependencies.scalaVersion,
Compile / smithy4sAllowedNamespaces := List("smithy.smithy4play"),
Compile / smithy4sAllowedNamespaces := List("smithy.smithy4play", "aws.protocols"),
Compile / smithy4sInputDirs := Seq(
(ThisBuild / baseDirectory).value / "smithy4play" / "src" / "resources" / "META_INF" / "smithy"
),
Expand All @@ -53,14 +53,15 @@ lazy val smithy4playTest = project
.enablePlugins(Smithy4sCodegenPlugin, PlayScala)
.settings(
sharedSettings,
scalaVersion := Dependencies.scalaVersion,
name := "smithy4playTest",
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" / "testDefinitions" / "test",
Compile / smithy4sInputDirs := Seq((ThisBuild / baseDirectory).value / "smithy4playTest" / "testSpecs"),
Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4playTest" / "app",
cleanFiles += (ThisBuild / baseDirectory).value / "smithy4playTest" / "app" / "specs" / "testDefinitions" / "test",
Compile / smithy4sInputDirs := Seq((ThisBuild / baseDirectory).value / "smithy4playTest" / "testSpecs"),
Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4playTest" / "app" / "specs",
Compile / smithy4sAllowedNamespaces := List("aws.protocols", "testDefinitions.test"),
libraryDependencies ++= Seq(
guice,
Dependencies.cats,
Expand Down
4 changes: 3 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ object Dependencies {
val typesafePlay = "com.typesafe.play" %% "play" % playVersion

val scalaVersion = "2.13.12"
val smithy4sVersion = "0.17.19"
val smithy4sVersion = "0.18.8"
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.2.8"
val alloyOpenapi = "com.disneystreaming.alloy" %% "alloy-openapi" % "0.2.8"
Expand All @@ -26,6 +27,7 @@ object Dependencies {
lazy val list = Seq(
smithyCore,
smithyJson,
smithyXml,
alloyCore,
alloyOpenapi,
smithy4sCompliance,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
addSbtPlugin("com.codecommit" %% "sbt-github-packages" % "0.5.3")
addSbtPlugin("org.wartremover" %% "sbt-wartremover" % "3.1.5")
addSbtPlugin("org.scalameta" %% "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.disneystreaming.smithy4s" %% "smithy4s-sbt-codegen" % "0.17.19")
addSbtPlugin("com.disneystreaming.smithy4s" %% "smithy4s-sbt-codegen" % "0.18.8")
addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.9.1")
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "2.0.9")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package de.innfactory.smithy4play

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.json.Json
import smithy4s.kinds.PolyFunction
import smithy4s.schema.CachedSchemaCompiler
import smithy4s.xml.Xml
import smithy4s.{ codecs, Blob }

object CodecDecider {

private val jsonCodecs = Json.payloadCodecs
.withJsoniterCodecCompiler(
Json.jsoniter
)

private val jsonEncoder: BlobEncoder.Compiler = jsonCodecs.encoders
private val jsonDecoder: BlobDecoder.Compiler = jsonCodecs.decoders
private val metadataEncoder = Metadata.Encoder
private val metadataDecoder: CachedSchemaCompiler[Metadata.Decoder] = Metadata.Decoder

def encoder(
contentType: Seq[String]
): CachedSchemaCompiler[codecs.BlobEncoder] =
contentType match {
case Seq(MimeTypes.JSON) => jsonEncoder
case Seq(MimeTypes.XML) => Xml.encoders
case _ =>
CachedSchemaCompiler
.getOrElse(smithy4s.codecs.StringAndBlobCodecs.encoders, jsonEncoder)
}

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

def requestEncoder(
contentType: Seq[String]
): CachedCompiler[EndpointRequest] =
HttpRestSchema.combineWriterCompilers(
metadataEncoder.mapK(
metadataPipe
),
encoder(contentType).mapK(
blobPipe
),
_ => false
)

def httpResponseDecoder(
contentType: Seq[String]
): CachedSchemaCompiler[Decoder[Either[Throwable, *], HttpResponse[Blob], *]] =
HttpRestSchema.combineDecoderCompilers[Either[Throwable, *], HttpResponse[Blob]](
metadataDecoder
.mapK(
Decoder
.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], *]]],
decoder(contentType)
.mapK(
Decoder.in[Either[PayloadError, *]].composeK[Blob, HttpResponse[Blob]](_.body)
)
.asInstanceOf[CachedSchemaCompiler[Decoder[Either[Throwable, *], HttpResponse[Blob], *]]],
_ => Right(())
)(eitherZipper)

def httpMessageEncoder(
contentType: Seq[String]
): CachedCompiler[HttpResponse[Blob]] =
HttpRestSchema.combineWriterCompilers(
metadataEncoder.mapK(
httpRequestMetadataPipe
),
encoder(contentType).mapK(
httpRequestBlobPipe
),
_ => false
)

private val httpRequestBodyLift: Writer[HttpResponse[Blob], Blob] =
Writer.lift[HttpResponse[Blob], Blob]((res, blob) => res.copy(body = blob))
private val httpRequestMetadataLift: Writer[HttpResponse[Blob], Metadata] =
Writer.lift[HttpResponse[Blob], Metadata]((res, metadata) =>
res.addHeaders(metadata.headers.map { case (insensitive, value) =>
(insensitive, value)
})
)
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], *]] =
smithy4s.codecs.Encoder.pipeToWriterK(httpRequestMetadataLift)

private val blobLift: Writer[EndpointRequest, Blob] =
Writer.lift[EndpointRequest, Blob]((res, blob) => res.copy(body = blob))
private val metadataLift: Writer[EndpointRequest, Metadata] =
Writer.lift[EndpointRequest, Metadata]((res, metadata) =>
res.addHeaders(metadata.headers.map { case (insensitive, value) =>
(insensitive, value)
})
)
private val blobPipe: PolyFunction[Encoder[Blob, *], Writer[EndpointRequest, *]] =
smithy4s.codecs.Encoder.pipeToWriterK[EndpointRequest, Blob](blobLift)
private val metadataPipe: PolyFunction[Encoder[Metadata, *], Writer[EndpointRequest, *]] =
smithy4s.codecs.Encoder.pipeToWriterK(metadataLift)

def decoder(
contentType: Seq[String]
): CachedSchemaCompiler[BlobDecoder] =
contentType match {
case Seq(MimeTypes.JSON) => jsonDecoder
case Seq(MimeTypes.XML) => Xml.decoders
case _ =>
CachedSchemaCompiler
.getOrElse(smithy4s.codecs.StringAndBlobCodecs.decoders, jsonDecoder)
}

}

This file was deleted.

Loading
Loading