Skip to content

Commit 6a468ee

Browse files
Validate member ids and targets
1 parent fd4ce01 commit 6a468ee

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

python-packages/smithy-core/smithy_core/schemas.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ def member(
177177
:param target: The schema the member is targeting.
178178
:param index: The member's index.
179179
"""
180+
id.expect_member()
181+
if target.member_target is not None:
182+
raise ExpectationNotMetException("Member targets must not be members.")
180183
resolved_traits = target.traits.copy()
181184
if member_traits:
182185
resolved_traits.update({t.id: t for t in member_traits})

python-packages/smithy-core/tests/unit/test_schemas.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,16 @@ def test_member_constructor():
104104
)
105105

106106
assert actual == expected
107+
108+
109+
def test_member_constructor_asserts_id():
110+
with pytest.raises(ExpectationNotMetException):
111+
Schema.member(id=ShapeID("smithy.example#foo"), target=STRING, index=0)
112+
113+
114+
def test_member_constructor_asserts_target_is_not_member():
115+
target = Schema.member(
116+
id=ShapeID("smithy.example#Spam$eggs"), target=STRING, index=0
117+
)
118+
with pytest.raises(ExpectationNotMetException):
119+
Schema.member(id=ShapeID("smithy.example#Foo$bar"), target=target, index=0)

0 commit comments

Comments
 (0)