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

Add validator for xmlFlattened + xmlName #2439

Merged

Conversation

milesziemer
Copy link
Contributor

Adds a validator for the xmlFlattened trait that checks if the member's target is a list that has a member with xmlName, and that xmlName doesn't match the name of the xmlFlattened member. xmlFlattened causes the xmlName of the list member to be ignored. This is called out in our docs:
https://smithy.io/2.0/spec/protocol-traits.html#flattened-list-serialization, but we were missing a validator for it. It is a warning because you might mean to do this, i.e. if the list is used in multiple places.

I also added some suppressions to our protocol tests that are testing the behavior for models that would trip up this validator.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Adds a validator for the xmlFlattened trait that checks if the member's
target is a list that has a member with xmlName, and that xmlName
doesn't match the name of the xmlFlattened member. xmlFlattened causes
the xmlName of the list member to be ignored. This is called out in our
docs:
https://smithy.io/2.0/spec/protocol-traits.html#flattened-list-serialization,
but we were missing a validator for it. It is a warning because you might
mean to do this, i.e. if the list is used in multiple places.

I also added some suppressions to our protocol tests that are testing
the behavior for models that would trip up this validator.
@milesziemer milesziemer requested a review from a team as a code owner November 1, 2024 17:50
@@ -1,5 +1,15 @@
$version: "2.0"

metadata suppressions = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it prohibitive to use the @suppress trait instead of a metadata suppression? It's a nice bit of documentation on that specific member as well that it's intending to test the behavior.

Comment on lines 34 to 37
model.getShape(member.getTarget())
.flatMap(Shape::asListShape)
.flatMap(listShape -> validateMemberTargetingList(member, listShape))
.ifPresent(events::add);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO reading this as a stream is harder than just reading ifs since we know the member target should exist.

Shape target = model.expectShape(member.getTarget());
if (target.isListShape()) {
    validateMemberTargetListing(member, targetList).ifPresent(events::add);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True I forgot we run that type of validation first, so we can expect the member target to exist.

@milesziemer milesziemer merged commit 857f05d into smithy-lang:main Nov 12, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants