Skip to content

Commit

Permalink
Fix rendering of deprecated annotation in mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostbuster91 committed Jul 26, 2023
1 parent 6bc465b commit 64028aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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]]
}
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")
final case class DeprecatedStructure(@deprecated(message = "N/A", since = "N/A") name: Option[String] = None, nameV2: Option[String] = None, strings: Option[List[String]] = None)
final case class DeprecatedStructure(@deprecated(message = "N/A", since = "N/A") strings: 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,9 @@ 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)),
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
13 changes: 9 additions & 4 deletions modules/codegen/src/smithy4s/codegen/internals/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,10 @@ 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 =>
deprecationAnnotation(f.hints).appendIf(_.nonEmpty)(Line.space) +
line"def ${fieldToRenderLine(f, noDefault = true)}"
}
)
}
}
Expand Down Expand Up @@ -1018,12 +1021,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
11 changes: 8 additions & 3 deletions sampleSpecs/deprecations.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ namespace smithy4s.example
use smithy4s.meta#adtMember

@deprecated(message: "A compelling reason", since: "0.0.1")
structure DeprecatedStructure {
@mixin
structure DeprecatedMixin {
@deprecated strings: 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 64028aa

Please sign in to comment.