Skip to content

Commit d9eb23d

Browse files
committed
Don't allow mixins in adtMember
1 parent f1e3737 commit d9eb23d

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

modules/protocol-tests/test/src/smithy4s/api/validation/AdtMemberTraitValidatorSpec.scala

+36
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ object AdtMemberTraitValidatorSpec extends FunSuite {
4747
success
4848
}
4949

50+
test("return an error when the union is a mixin") {
51+
52+
val events = eventsWithoutLocations(
53+
assembleModel(
54+
"""$version: "2"
55+
|namespace test
56+
|
57+
|use smithy4s.meta#adtMember
58+
|
59+
|@adtMember("test#MyUnion")
60+
|structure struct {
61+
| testing: String
62+
|}
63+
|
64+
|@mixin
65+
|union MyUnion {
66+
| unionMember: struct
67+
|}
68+
|""".stripMargin
69+
)
70+
)
71+
72+
val expected =
73+
ValidationEvent
74+
.builder()
75+
.id("TraitValue")
76+
.shapeId(ShapeId.fromParts("test", "struct"))
77+
.severity(Severity.ERROR)
78+
.message(
79+
"Error validating trait `smithy4s.meta#adtMember`: Shape ID `test#MyUnion` does not match selector `union :not([trait|mixin])`"
80+
)
81+
.build()
82+
83+
assert(events.contains(expected))
84+
}
85+
5086
test("return error when union does not target the structure") {
5187
val events = eventsWithoutLocations(
5288
assembleModel(

modules/protocol-tests/test/src/smithy4s/api/validation/AdtTraitValidatorSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object AdtTraitValidatorSpec extends FunSuite {
5252
.shapeId(ShapeId.fromParts("test", "MyUnion"))
5353
.severity(Severity.ERROR)
5454
.message(
55-
"Trait `smithy4s.meta#adt` cannot be applied to `test#MyUnion`. This trait may only be applied to shapes that match the following selector: :test(union :not([trait|mixin]))"
55+
"Trait `smithy4s.meta#adt` cannot be applied to `test#MyUnion`. This trait may only be applied to shapes that match the following selector: union :not([trait|mixin])"
5656
)
5757
.build()
5858

modules/protocol/resources/META-INF/smithy/smithy4s.meta.smithy

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ structure packedInputs {}
2424
/// which is the default behavior.
2525
/// Example usage: @adtMember(MyUnion)
2626
@trait(selector: "structure :not([trait|error])")
27-
@idRef(failWhenMissing: true, selector: "union")
27+
@idRef(failWhenMissing: true, selector: "union :not([trait|mixin])")
2828
string adtMember
2929

3030
/// Implies that all members of the union are annotated with the `adtMember` trait.
3131
/// Further signals that the `sealed trait` for this adt will extend the traits
3232
/// defined by any mixins that are present on all of the adt members.
33-
@trait(selector: ":test(union :not([trait|mixin]))")
33+
@trait(selector: "union :not([trait|mixin])")
3434
structure adt {}
3535

3636
// the indexedSeq trait can be added to list shapes in order for the generated collection

0 commit comments

Comments
 (0)