Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of deprecated annotation in mixins #1123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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