From 39940fb3825049a1e74e862e8c63b62e6f37cf91 Mon Sep 17 00:00:00 2001 From: Kasper Kondzielski Date: Wed, 26 Jul 2023 21:17:07 +0200 Subject: [PATCH] Fix rendering of deprecated annotation in mixins (#1123) Co-authored-by: ghostbuster91 Co-authored-by: David Francoeur --- .../smithy4s/codegen/internals/Renderer.scala | 16 ++++++++++++---- .../src/smithy4s/example/DeprecatedMixin.scala | 9 +++++++++ .../smithy4s/example/DeprecatedStructure.scala | 5 +++-- sampleSpecs/deprecations.smithy | 12 +++++++++--- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 modules/example/src/smithy4s/example/DeprecatedMixin.scala diff --git a/modules/codegen/src/smithy4s/codegen/internals/Renderer.scala b/modules/codegen/src/smithy4s/codegen/internals/Renderer.scala index cef9c7eff..03bd16ed4 100644 --- a/modules/codegen/src/smithy4s/codegen/internals/Renderer.scala +++ b/modules/codegen/src/smithy4s/codegen/internals/Renderer.scala @@ -624,7 +624,13 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self => } else Line.empty block(line"trait $name$ext") { lines( - fields.map(f => line"def ${fieldToRenderLine(f, noDefault = true)}") + fields.map { f => + lines( + deprecationAnnotation(f.hints), + Line.empty, + line"def ${fieldToRenderLine(f, noDefault = true)}" + ) + } ) } } @@ -884,12 +890,14 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self => ) } - deprecationAnnotation(hints).appendIf(_.nonEmpty)(Line.space) + - line"$name: " + tpeAndDefault + line"$name: " + tpeAndDefault } } private def renderArgs(fields: List[Field]): Line = fields - .map(fieldToRenderLine(_)) + .map { f => + deprecationAnnotation(f.hints).appendIf(_.nonEmpty)(Line.space) + + fieldToRenderLine(f) + } .intercalate(Line.comma) private def renderEnum( diff --git a/modules/example/src/smithy4s/example/DeprecatedMixin.scala b/modules/example/src/smithy4s/example/DeprecatedMixin.scala new file mode 100644 index 000000000..3266bddb9 --- /dev/null +++ b/modules/example/src/smithy4s/example/DeprecatedMixin.scala @@ -0,0 +1,9 @@ +package smithy4s.example + + +@deprecated(message = "A compelling reason", since = "0.0.1") +trait DeprecatedMixin { + @deprecated(message = "N/A", since = "N/A") + def strings: Option[List[String]] + def other: Option[List[String]] +} \ No newline at end of file diff --git a/modules/example/src/smithy4s/example/DeprecatedStructure.scala b/modules/example/src/smithy4s/example/DeprecatedStructure.scala index 2063b35de..e2de59b0a 100644 --- a/modules/example/src/smithy4s/example/DeprecatedStructure.scala +++ b/modules/example/src/smithy4s/example/DeprecatedStructure.scala @@ -8,7 +8,7 @@ import smithy4s.schema.Schema.string import smithy4s.schema.Schema.struct @deprecated(message = "A compelling reason", since = "0.0.1") -case class DeprecatedStructure(@deprecated(message = "N/A", since = "N/A") name: Option[String] = None, nameV2: Option[String] = None, strings: Option[List[String]] = None) +case class DeprecatedStructure(@deprecated(message = "N/A", since = "N/A") strings: Option[List[String]] = None, other: Option[List[String]] = None, @deprecated(message = "N/A", since = "N/A") name: Option[String] = None, nameV2: Option[String] = None) extends DeprecatedMixin object DeprecatedStructure extends ShapeTag.Companion[DeprecatedStructure] { val id: ShapeId = ShapeId("smithy4s.example", "DeprecatedStructure") @@ -17,9 +17,10 @@ object DeprecatedStructure extends ShapeTag.Companion[DeprecatedStructure] { ) implicit val schema: Schema[DeprecatedStructure] = struct( + Strings.underlyingSchema.optional[DeprecatedStructure]("strings", _.strings).addHints(smithy.api.Deprecated(message = None, since = None)), + Strings.underlyingSchema.optional[DeprecatedStructure]("other", _.other), string.optional[DeprecatedStructure]("name", _.name).addHints(smithy.api.Deprecated(message = None, since = None)), string.optional[DeprecatedStructure]("nameV2", _.nameV2), - Strings.underlyingSchema.optional[DeprecatedStructure]("strings", _.strings), ){ DeprecatedStructure.apply }.withId(id).addHints(hints) diff --git a/sampleSpecs/deprecations.smithy b/sampleSpecs/deprecations.smithy index bf11740ad..5157d2598 100644 --- a/sampleSpecs/deprecations.smithy +++ b/sampleSpecs/deprecations.smithy @@ -3,10 +3,16 @@ namespace smithy4s.example use smithy4s.meta#adtMember @deprecated(message: "A compelling reason", since: "0.0.1") -structure DeprecatedStructure { +@mixin +structure DeprecatedMixin { + @deprecated strings: Strings, + other: Strings +} + +@deprecated(message: "A compelling reason", since: "0.0.1") +structure DeprecatedStructure with [DeprecatedMixin] { @deprecated name: String, - nameV2: String, - strings: Strings + nameV2: String } @deprecated