diff --git a/README.md b/README.md index 66f07e1..d8eee5a 100644 --- a/README.md +++ b/README.md @@ -136,14 +136,16 @@ After the `addMembers` transformer runs, `MyStruct` has the original `original` ## `removeTraits` -Unlike the others, this one isn't driven by a trait — it's model-wide, so there's no shape to attach it to. It's configured by the `removeTraits` metadata key, whose type is declared with Smithy's [`@metadata` trait](https://smithy.io/2.0/spec/model.html#metadata-trait), so the value is validated as part of loading the model. +Unlike the others, this one isn't driven by a trait — it's model-wide, so there's no shape to attach it to. It's configured by the `smithytransformations#removeTraits` metadata key, whose type is declared with Smithy's [`@metadata` trait](https://smithy.io/2.0/spec/model.html#metadata-trait), so the value is validated as part of loading the model. + +Metadata keys are plain strings — Smithy attaches no namespace meaning to the `#`. It's qualified here purely to avoid collisions: metadata is merged across every model loaded together, so a bare `removeTraits` would clash with any other library that picked the same word. (The transformer's *name*, used in `smithy4sModelTransformers` and `smithy-build.json`, is just `removeTraits`.) Each entry is a [selector](https://smithy.io/2.0/spec/selectors.html) matching the **trait definition shapes** to strip: ```smithy $version: "2" -metadata "removeTraits" = [ +metadata "smithytransformations#removeTraits" = [ "[trait|trait][id|namespace = 'smithy.rules']" // every trait in the namespace "[id = 'smithy.api#deprecated']" // just this one trait ] diff --git a/smithy4sExample/src/main/smithy/example.smithy b/smithy4sExample/src/main/smithy/example.smithy index 10c255d..f6561bd 100644 --- a/smithy4sExample/src/main/smithy/example.smithy +++ b/smithy4sExample/src/main/smithy/example.smithy @@ -1,7 +1,7 @@ $version: "2" // every trait in the `custom` namespace is stripped from the model before codegen runs -metadata "removeTraits" = ["[trait|trait][id|namespace = 'custom']"] +metadata "smithytransformations#removeTraits" = ["[trait|trait][id|namespace = 'custom']"] namespace example diff --git a/tests/src/test/scala/smithytransformations/RemoveTraitsTest.scala b/tests/src/test/scala/smithytransformations/RemoveTraitsTest.scala index 142eb8c..35d73cd 100644 --- a/tests/src/test/scala/smithytransformations/RemoveTraitsTest.scala +++ b/tests/src/test/scala/smithytransformations/RemoveTraitsTest.scala @@ -32,7 +32,7 @@ class RemoveTraitsTest extends FunSuite { customTraits, """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][id|namespace = 'custom']"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][id|namespace = 'custom']"] | |namespace example | @@ -52,7 +52,7 @@ class RemoveTraitsTest extends FunSuite { customTraits, """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][id|namespace = 'custom']"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][id|namespace = 'custom']"] | |namespace example | @@ -71,7 +71,7 @@ class RemoveTraitsTest extends FunSuite { customTraits, """|$version: "2" | - |metadata "removeTraits" = ["[id = 'custom#alpha']"] + |metadata "smithytransformations#removeTraits" = ["[id = 'custom#alpha']"] | |namespace example | @@ -89,7 +89,7 @@ class RemoveTraitsTest extends FunSuite { customTraits, """|$version: "2" | - |metadata "removeTraits" = ["[id = 'custom#alpha']"] + |metadata "smithytransformations#removeTraits" = ["[id = 'custom#alpha']"] | |namespace example | @@ -111,7 +111,7 @@ class RemoveTraitsTest extends FunSuite { otherTraits, """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][id|namespace = 'custom']", "[id = 'other#gamma']"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][id|namespace = 'custom']", "[id = 'other#gamma']"] | |namespace example | @@ -133,7 +133,7 @@ class RemoveTraitsTest extends FunSuite { otherTraits, """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][id|namespace = 'custom']", "[id = 'other#gamma']"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][id|namespace = 'custom']", "[id = 'other#gamma']"] | |namespace example | @@ -164,7 +164,7 @@ class RemoveTraitsTest extends FunSuite { val model = """|$version: "2" | - |metadata "removeTraits" = [] + |metadata "smithytransformations#removeTraits" = [] | |namespace example | @@ -180,7 +180,7 @@ class RemoveTraitsTest extends FunSuite { val model = """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][id|namespace = 'nope']"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][id|namespace = 'nope']"] | |namespace example | @@ -196,7 +196,7 @@ class RemoveTraitsTest extends FunSuite { val errors = validationErrorsFor( """|$version: "2" | - |metadata "removeTraits" = "custom" + |metadata "smithytransformations#removeTraits" = "custom" | |namespace example | @@ -204,7 +204,7 @@ class RemoveTraitsTest extends FunSuite { |""".stripMargin ) assert( - errors.exists(_.contains("removeTraits")), + errors.exists(_.contains("smithytransformations#removeTraits")), errors.mkString("\n"), ) } @@ -213,7 +213,7 @@ class RemoveTraitsTest extends FunSuite { val errors = validationErrorsFor( """|$version: "2" | - |metadata "removeTraits" = [""] + |metadata "smithytransformations#removeTraits" = [""] | |namespace example | @@ -221,7 +221,7 @@ class RemoveTraitsTest extends FunSuite { |""".stripMargin ) assert( - errors.exists(_.contains("removeTraits")), + errors.exists(_.contains("smithytransformations#removeTraits")), errors.mkString("\n"), ) } @@ -242,7 +242,7 @@ class RemoveTraitsTest extends FunSuite { |""".stripMargin, """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][trait|smithy.api#unstable]"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][trait|smithy.api#unstable]"] | |namespace example | @@ -270,7 +270,7 @@ class RemoveTraitsTest extends FunSuite { |""".stripMargin, """|$version: "2" | - |metadata "removeTraits" = ["[trait|trait][trait|smithy.api#unstable]"] + |metadata "smithytransformations#removeTraits" = ["[trait|trait][trait|smithy.api#unstable]"] | |namespace example | @@ -289,7 +289,7 @@ class RemoveTraitsTest extends FunSuite { val model = loadModel( """|$version: "2" | - |metadata "removeTraits" = ["[[[not a selector"] + |metadata "smithytransformations#removeTraits" = ["[[[not a selector"] | |namespace example | diff --git a/transformation/src/main/java/smithytransformations/RemoveTraits.java b/transformation/src/main/java/smithytransformations/RemoveTraits.java index 7504483..0bf8409 100644 --- a/transformation/src/main/java/smithytransformations/RemoveTraits.java +++ b/transformation/src/main/java/smithytransformations/RemoveTraits.java @@ -33,7 +33,7 @@ /** * Strips traits off every shape in the model. * - *
Configured by the {@code removeTraits} metadata key, whose shape (and therefore whose + *
Configured by the {@code smithytransformations#removeTraits} metadata key, whose shape (and therefore whose * validation) is declared with {@code @metadata} in {@code smithytransformations.smithy}. Metadata * rather than a trait, because the transformation is model-wide and has no shape to attach itself * to. @@ -45,7 +45,7 @@ public final class RemoveTraits implements ProjectionTransformer { /** Metadata key holding the selectors. Kept in sync with the {@code @metadata} declaration. */ - static final String METADATA_KEY = "removeTraits"; + static final String METADATA_KEY = "smithytransformations#removeTraits"; @Override public String getName() { diff --git a/transformation/src/main/resources/META-INF/smithy/smithytransformations.smithy b/transformation/src/main/resources/META-INF/smithy/smithytransformations.smithy index cac8540..4f81474 100644 --- a/transformation/src/main/resources/META-INF/smithy/smithytransformations.smithy +++ b/transformation/src/main/resources/META-INF/smithy/smithytransformations.smithy @@ -38,7 +38,7 @@ map TraitMap { /// Selectors matching the trait definition shapes whose traits should be stripped off /// every shape in the model, e.g. `[trait|trait][id|namespace = 'smithy.rules']`. -@metadata(key: "removeTraits") +@metadata(key: "smithytransformations#removeTraits") list RemoveTraits { member: RemoveTraitsSelector }