-
Notifications
You must be signed in to change notification settings - Fork 70
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
Render deprecation hints #599
Conversation
case _ => Lines.empty | ||
} | ||
|
||
private def deprecationAnnotation(hints: List[Hint]): Line = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the implementation feels a bit dirty, suggestions welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing I'd change here is have an extra map, before the that's already there where I call renderStringLiteral
before building the line
to avoid ${renderStringLiteral(msg)}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I actually like that renderStringLiteral
is being interpolated (as long as it doesn't break the line)
@@ -166,6 +185,7 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self => | |||
val name = s.name | |||
val nameGen = NameRef(s"${name}Gen") | |||
lines( | |||
deprecationAnnotation(s.hints), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought it would make sense to deprecate just the service trait and type alias, but we could deprecate the companion object / val
alias as well. I don't have a strong opinion on this.
@@ -273,7 +273,8 @@ private[codegen] class SmithyToIR(model: Model, namespace: String) { | |||
value.getName().asScala, | |||
value.getValue, | |||
index | |||
) | |||
), | |||
hints = Nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK 1.x enums don't allow hints on values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct
val values = shape | ||
.getEnumValues() | ||
.asScala | ||
.map { case (name, value) => | ||
EnumValue(name, value, name) | ||
val member = shape.getMember(name).get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels a bit odd to do the lookup like this, but it's not that much repetition and it should be safe at all times.
project/Smithy4sBuildPlugin.scala
Outdated
// Ignores warnings in code using the deprecated Enum trait. | ||
scalacOptions += "-Wconf:msg=object Enum in package api is deprecated:silent" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI here's what Enum now generates as:
@deprecated(message = "The enum trait is replaced by the enum shape in Smithy 2.0", since = "2.0")
object Enum extends Newtype[List[EnumDefinition]] {
val id: ShapeId = ShapeId("smithy.api", "enum")
val hints : Hints = Hints(
smithy.api.Documentation("Constrains the acceptable values of a string to a fixed set\nof constant values."),
smithy.api.Trait(selector = Some("string :not(enum)"), structurallyExclusive = None, conflicts = None, breakingChanges = Some(List(smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.PRESENCE.widen, severity = smithy.api.TraitChangeSeverity.ERROR.widen, path = None, message = None)))),
smithy.api.Deprecated(message = Some("The enum trait is replaced by the enum shape in Smithy 2.0"), since = Some("2.0")),
)
val underlyingSchema : Schema[List[EnumDefinition]] = list(EnumDefinition.schema).withId(id).addHints(hints).validated(smithy.api.Length(min = Some(1), max = None))
implicit val schema : Schema[Enum] = recursive(bijection(underlyingSchema, asBijection))
}
39686e1
to
d5b5a81
Compare
I'll get back to this after the weekend, most likely |
@Baccata I think this is ready to go from my side |
@@ -988,4 +1023,15 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self => | |||
case _ => _ => line"null" | |||
} | |||
|
|||
private def renderStringLiteral(raw: String): Line = { | |||
import scala.reflect.runtime.universe._ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the import used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literal
and Constant
import smithy4s.schema.Schema.struct | ||
import smithy4s.ShapeTag | ||
|
||
@deprecated(message = "A compelling reason", since = "0.0.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahaha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job, it's more work that I had anticipated
kudos on the work on dynamic, this PR serves as a great reference if for changes that would need to apply there as well
@@ -742,6 +740,8 @@ private[codegen] class SmithyToIR(model: Model, namespace: String) { | |||
// traits from the synthetic namespace, e.g. smithy.synthetic.enum | |||
// don't have shapes in the model - so we can't generate hints for them. | |||
.filterNot(_.toShapeId().getNamespace() == "smithy.synthetic") | |||
// enumValue can be derived from enum schemas anyway, so we're removing it from hints | |||
.filterNot(_.toShapeId().toString() == "smithy.api#enumValue") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thy shall not use .toString
when there is an alternative (in this case, ShapeId.fromParts("smithy.api", "enumValue")
or probably even EnumValueTrait.ID
or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now you're just nitpicking :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, just .toString trauma 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:heavy-nodding:
Made a separate commit for the actual implementation so that you can see how it affects the deprecated shapes:
files in
modules/example
of this commitI think this doesn't have to go into 0.17 as it wouldn't make breaking changes.
Edit: about the above, I think this might be source breaking in a way (people might have fatal warnings on). Let's stick it into 0.17.
Solves the deprecation part of #256