-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add validator for xmlFlattened + xmlName #2439
Conversation
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.
@@ -1,5 +1,15 @@ | |||
$version: "2.0" | |||
|
|||
metadata suppressions = [ |
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.
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.
model.getShape(member.getTarget()) | ||
.flatMap(Shape::asListShape) | ||
.flatMap(listShape -> validateMemberTargetingList(member, listShape)) | ||
.ifPresent(events::add); |
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.
IMO reading this as a stream is harder than just reading if
s since we know the member target should exist.
Shape target = model.expectShape(member.getTarget());
if (target.isListShape()) {
validateMemberTargetListing(member, targetList).ifPresent(events::add);
}
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.
True I forgot we run that type of validation first, so we can expect the member target to exist.
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.