Skip to content

Commit

Permalink
Fix rendering of deprecated annotation in mixins (#1123)
Browse files Browse the repository at this point in the history
Co-authored-by: ghostbuster91 <ghostbuster91@users.noreply.github.com>
Co-authored-by: David Francoeur <dfrancoeur04@gmail.com>
  • Loading branch information
3 people committed Jul 26, 2023
1 parent a0186ae commit 39940fb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
16 changes: 12 additions & 4 deletions modules/codegen/src/smithy4s/codegen/internals/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
)
}
)
}
}
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions modules/example/src/smithy4s/example/DeprecatedMixin.scala
Original file line number Diff line number Diff line change
@@ -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]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions sampleSpecs/deprecations.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39940fb

Please sign in to comment.