From 31b026277fb872f8258783f8c635645813bbabcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20M=C3=A9lois?= Date: Mon, 31 Jan 2022 19:22:09 +0100 Subject: [PATCH] Render ShapeTags for everything (#89) Since Hint keys are now ShapeTags, they are conceptually no longer specific to keys, so might as well render them for all shapes. --- modules/codegen/src/smithy4s/codegen/Renderer.scala | 10 +++++----- modules/core/src/smithy4s/HintMask.scala | 4 ++-- .../src/smithy4s/example/ArbitraryDataTest.scala | 2 +- modules/example/src/smithy4s/example/Foo.scala | 2 +- .../example/src/smithy4s/example/GetFooOutput.scala | 2 +- .../example/src/smithy4s/example/GetObjectInput.scala | 2 +- .../example/src/smithy4s/example/GetObjectOutput.scala | 2 +- .../src/smithy4s/example/GetStreamedObjectInput.scala | 2 +- .../src/smithy4s/example/GetStreamedObjectOutput.scala | 2 +- modules/example/src/smithy4s/example/LowHigh.scala | 2 +- modules/example/src/smithy4s/example/NoMoreSpace.scala | 2 +- .../example/src/smithy4s/example/ObjectService.scala | 4 ++-- .../example/src/smithy4s/example/PutObjectInput.scala | 2 +- .../src/smithy4s/example/PutStreamedObjectInput.scala | 2 +- modules/example/src/smithy4s/example/ServerError.scala | 2 +- 15 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/codegen/src/smithy4s/codegen/Renderer.scala b/modules/codegen/src/smithy4s/codegen/Renderer.scala index 8afe95bef..c2084e070 100644 --- a/modules/codegen/src/smithy4s/codegen/Renderer.scala +++ b/modules/codegen/src/smithy4s/codegen/Renderer.scala @@ -346,7 +346,7 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self => } } } else line(decl), - obj(name, ext = hintKey(name, hints))( + obj(name, ext = shapeTag(name))( renderId(name), newline, renderHintsValWithId(hints), @@ -417,7 +417,7 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self => val imports = alts.foldMap(_.tpe.imports) ++ syntaxImport lines( s"sealed trait $name extends scala.Product with scala.Serializable", - obj(name, ext = hintKey(name, hints))( + obj(name, ext = shapeTag(name))( renderId(name), newline, renderHintsValWithId(hints), @@ -476,7 +476,7 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self => hints: List[Hint] ): RenderResult = lines( s"sealed abstract class $name(val value: String, val ordinal: Int) extends scala.Product with scala.Serializable", - obj(name, ext = s"$Enumeration_[$name]", w = hintKey(name, hints))( + obj(name, ext = s"$Enumeration_[$name]", w = shapeTag(name))( renderId(name), newline, renderHintsValWithId(hints), @@ -667,8 +667,8 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self => if (h.isEmpty) "" else h.mkString(", ") } - private def hintKey(name: String, hints: List[Hint]): String = - if (hints.contains(Hint.Trait)) s"$ShapeTag_.Companion[$name]" else "" + private def shapeTag(name: String): String = + s"$ShapeTag_.Companion[$name]" type TopLevel = Boolean type InCollection = Boolean diff --git a/modules/core/src/smithy4s/HintMask.scala b/modules/core/src/smithy4s/HintMask.scala index e6fda4f7e..09ec3ba73 100644 --- a/modules/core/src/smithy4s/HintMask.scala +++ b/modules/core/src/smithy4s/HintMask.scala @@ -27,8 +27,8 @@ object HintMask { def empty: HintMask = apply() - def apply(hintKeys: ShapeTag[_]*): HintMask = { - new Impl(hintKeys.toSet) + def apply(shapeTags: ShapeTag[_]*): HintMask = { + new Impl(shapeTags.toSet) } private[this] case object Permissive extends HintMask { diff --git a/modules/example/src/smithy4s/example/ArbitraryDataTest.scala b/modules/example/src/smithy4s/example/ArbitraryDataTest.scala index c3d10fb51..9a850b206 100644 --- a/modules/example/src/smithy4s/example/ArbitraryDataTest.scala +++ b/modules/example/src/smithy4s/example/ArbitraryDataTest.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class ArbitraryDataTest() -object ArbitraryDataTest { +object ArbitraryDataTest extends smithy4s.ShapeTag.Companion[ArbitraryDataTest] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "ArbitraryDataTest") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/Foo.scala b/modules/example/src/smithy4s/example/Foo.scala index 54dedca6f..3d5b2cda2 100644 --- a/modules/example/src/smithy4s/example/Foo.scala +++ b/modules/example/src/smithy4s/example/Foo.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ sealed trait Foo extends scala.Product with scala.Serializable -object Foo { +object Foo extends smithy4s.ShapeTag.Companion[Foo] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "Foo") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/GetFooOutput.scala b/modules/example/src/smithy4s/example/GetFooOutput.scala index feb4099db..64f6cbabe 100644 --- a/modules/example/src/smithy4s/example/GetFooOutput.scala +++ b/modules/example/src/smithy4s/example/GetFooOutput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class GetFooOutput(foo: Option[Foo] = None) -object GetFooOutput { +object GetFooOutput extends smithy4s.ShapeTag.Companion[GetFooOutput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetFooOutput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/GetObjectInput.scala b/modules/example/src/smithy4s/example/GetObjectInput.scala index 3dff558fc..c2f65d098 100644 --- a/modules/example/src/smithy4s/example/GetObjectInput.scala +++ b/modules/example/src/smithy4s/example/GetObjectInput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class GetObjectInput(key: ObjectKey, bucketName: BucketName) -object GetObjectInput { +object GetObjectInput extends smithy4s.ShapeTag.Companion[GetObjectInput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetObjectInput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/GetObjectOutput.scala b/modules/example/src/smithy4s/example/GetObjectOutput.scala index 6b8b70139..049d3be24 100644 --- a/modules/example/src/smithy4s/example/GetObjectOutput.scala +++ b/modules/example/src/smithy4s/example/GetObjectOutput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class GetObjectOutput(size: ObjectSize, data: Option[String] = None) -object GetObjectOutput { +object GetObjectOutput extends smithy4s.ShapeTag.Companion[GetObjectOutput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetObjectOutput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/GetStreamedObjectInput.scala b/modules/example/src/smithy4s/example/GetStreamedObjectInput.scala index 077205327..6db5c5e73 100644 --- a/modules/example/src/smithy4s/example/GetStreamedObjectInput.scala +++ b/modules/example/src/smithy4s/example/GetStreamedObjectInput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class GetStreamedObjectInput(key: String) -object GetStreamedObjectInput { +object GetStreamedObjectInput extends smithy4s.ShapeTag.Companion[GetStreamedObjectInput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetStreamedObjectInput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/GetStreamedObjectOutput.scala b/modules/example/src/smithy4s/example/GetStreamedObjectOutput.scala index 843dec8a6..aa5950832 100644 --- a/modules/example/src/smithy4s/example/GetStreamedObjectOutput.scala +++ b/modules/example/src/smithy4s/example/GetStreamedObjectOutput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class GetStreamedObjectOutput() -object GetStreamedObjectOutput { +object GetStreamedObjectOutput extends smithy4s.ShapeTag.Companion[GetStreamedObjectOutput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetStreamedObjectOutput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/LowHigh.scala b/modules/example/src/smithy4s/example/LowHigh.scala index ee8f607b1..d6d7eda69 100644 --- a/modules/example/src/smithy4s/example/LowHigh.scala +++ b/modules/example/src/smithy4s/example/LowHigh.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ sealed abstract class LowHigh(val value: String, val ordinal: Int) extends scala.Product with scala.Serializable -object LowHigh extends smithy4s.Enumeration[LowHigh] { +object LowHigh extends smithy4s.Enumeration[LowHigh] with smithy4s.ShapeTag.Companion[LowHigh] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "LowHigh") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/NoMoreSpace.scala b/modules/example/src/smithy4s/example/NoMoreSpace.scala index 61689467f..0f5a15385 100644 --- a/modules/example/src/smithy4s/example/NoMoreSpace.scala +++ b/modules/example/src/smithy4s/example/NoMoreSpace.scala @@ -5,7 +5,7 @@ import smithy4s.syntax._ case class NoMoreSpace(message: String, foo: Option[Foo] = None) extends Throwable { override def getMessage() : String = message } -object NoMoreSpace { +object NoMoreSpace extends smithy4s.ShapeTag.Companion[NoMoreSpace] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "NoMoreSpace") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/ObjectService.scala b/modules/example/src/smithy4s/example/ObjectService.scala index a982d82f4..1719bbdaa 100644 --- a/modules/example/src/smithy4s/example/ObjectService.scala +++ b/modules/example/src/smithy4s/example/ObjectService.scala @@ -81,7 +81,7 @@ object ObjectServiceGen extends smithy4s.Service[ObjectServiceGen, ObjectService } } sealed trait PutObjectError extends scala.Product with scala.Serializable - object PutObjectError { + object PutObjectError extends smithy4s.ShapeTag.Companion[PutObjectError] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "PutObjectError") val hints : smithy4s.Hints = smithy4s.Hints( @@ -135,7 +135,7 @@ object ObjectServiceGen extends smithy4s.Service[ObjectServiceGen, ObjectService } } sealed trait GetObjectError extends scala.Product with scala.Serializable - object GetObjectError { + object GetObjectError extends smithy4s.ShapeTag.Companion[GetObjectError] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetObjectError") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/PutObjectInput.scala b/modules/example/src/smithy4s/example/PutObjectInput.scala index 031c3bdba..363253838 100644 --- a/modules/example/src/smithy4s/example/PutObjectInput.scala +++ b/modules/example/src/smithy4s/example/PutObjectInput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class PutObjectInput(key: ObjectKey, bucketName: BucketName, data: String, foo: Option[LowHigh] = None, someValue: Option[SomeValue] = None) -object PutObjectInput { +object PutObjectInput extends smithy4s.ShapeTag.Companion[PutObjectInput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "PutObjectInput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/PutStreamedObjectInput.scala b/modules/example/src/smithy4s/example/PutStreamedObjectInput.scala index dce07b431..ce3479317 100644 --- a/modules/example/src/smithy4s/example/PutStreamedObjectInput.scala +++ b/modules/example/src/smithy4s/example/PutStreamedObjectInput.scala @@ -3,7 +3,7 @@ package smithy4s.example import smithy4s.syntax._ case class PutStreamedObjectInput(key: String) -object PutStreamedObjectInput { +object PutStreamedObjectInput extends smithy4s.ShapeTag.Companion[PutStreamedObjectInput] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "PutStreamedObjectInput") val hints : smithy4s.Hints = smithy4s.Hints( diff --git a/modules/example/src/smithy4s/example/ServerError.scala b/modules/example/src/smithy4s/example/ServerError.scala index 69345d9fa..f1c8e176f 100644 --- a/modules/example/src/smithy4s/example/ServerError.scala +++ b/modules/example/src/smithy4s/example/ServerError.scala @@ -5,7 +5,7 @@ import smithy4s.syntax._ case class ServerError(message: Option[String] = None) extends Throwable { override def getMessage() : String = message.orNull } -object ServerError { +object ServerError extends smithy4s.ShapeTag.Companion[ServerError] { val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "ServerError") val hints : smithy4s.Hints = smithy4s.Hints(