Skip to content

Commit

Permalink
Merge pull request #1022 from disneystreaming/update-smithy-model
Browse files Browse the repository at this point in the history
Update smithy-model to 1.31.0, alloy to 0.2.2
  • Loading branch information
daddykotex authored Jun 13, 2023
2 parents 68a10cc + d995816 commit 9818649
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
4 changes: 2 additions & 2 deletions modules/example/src/smithy4s/example/OrderType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import smithy4s.schema.Schema.struct
import smithy4s.schema.Schema.union

/** Our order types have different ways to identify a product
* Except for preview orders, these don't have an ID
* Except for preview orders, these don't have an ID
*/
sealed trait OrderType extends scala.Product with scala.Serializable {
@inline final def widen: OrderType = this
Expand All @@ -19,7 +19,7 @@ object OrderType extends ShapeTag.Companion[OrderType] {
val id: ShapeId = ShapeId("smithy4s.example", "OrderType")

val hints: Hints = Hints(
smithy.api.Documentation("Our order types have different ways to identify a product\nExcept for preview orders, these don\'t have an ID"),
smithy.api.Documentation("Our order types have different ways to identify a product\nExcept for preview orders, these don\'t have an ID "),
)

case class OnlineCase(online: OrderNumber) extends OrderType
Expand Down
2 changes: 1 addition & 1 deletion modules/example/src/smithy4s/example/TestTrait.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import smithy4s.schema.Schema.struct

/** @param orderType
* Our order types have different ways to identify a product
* Except for preview orders, these don't have an ID
* Except for preview orders, these don't have an ID
*/
case class TestTrait(orderType: Option[OrderType] = None)
object TestTrait extends ShapeTag.Companion[TestTrait] {
Expand Down
17 changes: 9 additions & 8 deletions modules/http4s/src/smithy4s/http4s/EntityCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.http4s._
import org.http4s.headers.`Content-Type`
import smithy4s.http.BodyPartial
import smithy4s.http.CodecAPI
import smithy4s.http.Metadata
import smithy4s.schema.Primitive

trait EntityCompiler[F[_]] {

Expand Down Expand Up @@ -87,19 +87,20 @@ object EntityCompiler {
): EntityEncoder[F, A] = {
val codecA: codecAPI.Codec[A] = codecAPI.compileCodec(schema, cache)
val mediaType = MediaType.unsafeParse(codecAPI.mediaType(codecA).value)
val expectBody = Metadata.PartialDecoder
.fromSchema(schema)
.total
.isEmpty // expect body if metadata decoder is not total
if (expectBody) {
val isEmpty = schema match {
case Schema.PrimitiveSchema(_, _, Primitive.PUnit) => true
case _ => false
}

if (isEmpty) {
EntityEncoder.emptyEncoder
} else {
EntityEncoder
.byteArrayEncoder[F]
.withContentType(
`Content-Type`(mediaType)
)
.contramap[A]((a: A) => codecAPI.writeToArray(codecA, a))
} else {
EntityEncoder.emptyEncoder
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private[http4s] class SmithyHttp4sServerEndpointImpl[F[_], Op[_, _, _, _, _], I,

run
.recoverWith(transformError)
.flatMap(successResponse)
.map(successResponse)
.handleErrorWith(errorResponse)
}))

Expand Down Expand Up @@ -196,18 +196,17 @@ private[http4s] class SmithyHttp4sServerEndpointImpl[F[_], Op[_, _, _, _, _], I,
.map { case (k, v) => k -> v.map(_._2).toList }
).pure[F]

private def successResponse(output: O): F[Response[F]] = {
private def successResponse(output: O): Response[F] = {
val outputMetadata = outputMetadataEncoder.encode(output)
val outputHeaders = toHeaders(outputMetadata.headers)
val statusCode = outputMetadata.statusCode.getOrElse(httpEndpoint.code)
val httpStatus = status(statusCode)

putHeaders(Response[F](httpStatus), outputHeaders)
.withEntity(output)
.pure[F]
}

def compileErrorable(errorable: Errorable[E]): E => Response[F] = {
private def compileErrorable(errorable: Errorable[E]): E => Response[F] = {
def errorHeaders(errorLabel: String, metadata: Metadata): Headers =
toHeaders(metadata.headers).put(errorTypeHeader -> errorLabel)
val errorUnionSchema = errorable.error
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Dependencies {

val Smithy = new {
val org = "software.amazon.smithy"
val smithyVersion = "1.30.0"
val smithyVersion = "1.31.0"
val model = org % "smithy-model" % smithyVersion
val testTraits = org % "smithy-protocol-test-traits" % smithyVersion
val build = org % "smithy-build" % smithyVersion
Expand All @@ -30,7 +30,7 @@ object Dependencies {

val Alloy = new {
val org = "com.disneystreaming.alloy"
val alloyVersion = "0.1.18"
val alloyVersion = "0.2.2"
val core = org % "alloy-core" % alloyVersion
val openapi = org %% "alloy-openapi" % alloyVersion
val `protocol-tests` = org % "alloy-protocol-tests" % alloyVersion
Expand Down
9 changes: 3 additions & 6 deletions smithy-build.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"imports": [
"./sampleSpecs",
"./modules/protocol/resources"
],
"imports": ["./sampleSpecs", "./modules/protocol/resources"],
"mavenDependencies": [
"software.amazon.smithy:smithy-protocol-test-traits:1.26.0",
"com.disneystreaming.alloy:alloy-core:0.1.9"
"software.amazon.smithy:smithy-protocol-test-traits:1.31.0",
"com.disneystreaming.alloy:alloy-core:0.2.2"
]
}

0 comments on commit 9818649

Please sign in to comment.