-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from innFactory/feature/update-smithy4s
chore: update smithy4s version from 0.17.2 to 0.17.4
Showing
9 changed files
with
86 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
sbt.version = 1.7.2 | ||
sbt.version = 1.8.2 | ||
scala.version = 2.13.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.3") | ||
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.0.11") | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") | ||
addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.17.2") | ||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19") | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3") | ||
addSbtPlugin("com.codecommit" %% "sbt-github-packages" % "0.5.3") | ||
addSbtPlugin("org.wartremover" %% "sbt-wartremover" % "3.0.11") | ||
addSbtPlugin("org.scalameta" %% "sbt-scalafmt" % "2.5.0") | ||
addSbtPlugin("com.disneystreaming.smithy4s" %% "smithy4s-sbt-codegen" % "0.17.4") | ||
addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.8.19") | ||
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.9.3") | ||
|
||
ThisBuild / dependencyOverrides ++= Seq( | ||
"org.scala-lang.modules" %% "scala-xml" % "1.3.0" | ||
) |
35 changes: 35 additions & 0 deletions
35
smithy4play/src/main/scala/de/innfactory/smithy4play/CodecUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.innfactory.smithy4play | ||
|
||
import smithy4s.{ HintMask, Schema } | ||
import smithy4s.http.{ CodecAPI, PayloadError } | ||
import smithy4s.http.json.codecs | ||
import smithy4s.internals.InputOutput | ||
|
||
object CodecUtils { | ||
|
||
private val codecs: codecs = | ||
smithy4s.http.json.codecs(alloy.SimpleRestJson.protocol.hintMask ++ HintMask(InputOutput)) | ||
|
||
def writeInputToBody[I](input: I, inputSchema: Schema[I], codecAPI: CodecAPI): Array[Byte] = { | ||
val codec = codecAPI.compileCodec(inputSchema) | ||
codecAPI.writeToArray(codec, input) | ||
} | ||
|
||
def readFromBytes[E](data: Array[Byte], inputSchema: Schema[E], codecAPI: CodecAPI): Either[PayloadError, E] = | ||
codecAPI.decodeFromByteArray(codecAPI.compileCodec(inputSchema), data) | ||
|
||
def writeEntityToJsonBytes[E](e: E, schema: Schema[E]) = writeInputToBody[E](e, schema, codecs) | ||
|
||
def readFromJsonBytes[E](bytes: Array[Byte], schema: Schema[E]): Option[E] = | ||
readFromBytes(bytes, schema, codecs).toOption | ||
|
||
def extractCodec(headers: Map[String, Seq[String]]): CodecAPI = { | ||
val contentType = | ||
headers.getOrElse("content-type", List("application/json")) | ||
val codecApi = contentType match { | ||
case List("application/json") => codecs | ||
case _ => CodecAPI.nativeStringsAndBlob(codecs) | ||
} | ||
codecApi | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package models | ||
|
||
import play.api.libs.json.Json | ||
|
||
case class TestJson(message: Option[String]) | ||
|
||
object TestJson { | ||
implicit val format = Json.format[TestJson] | ||
} |