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

Fix resource identifier collision and validation #1453

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

mtdowling
Copy link
Member

When loading a model with multiple members bound to the same resource identifier, Smithy failed with an error in IdentifierBindingIndex due to Collectors.toMap:

Duplicate key X (attempted merging values y and z)

This change updates IdentifierBindingIndex to ignore collisions. However this means that colliding resource identifier bindings would be ignored (which is arguably worse than failing to load the model since it wouldn't ever flag these issues, and retroactively enforcing things is always challenging). To address this, I added validation to detect when members with the resourceIdentifier trait conflict with members of the same binding name or members that have the same resourceIdentifier trait.

Issue #, if available:

Description of changes:

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

When loading a model with multiple members bound to the same resource identifier,
Smithy failed with an error in IdentifierBindingIndex due to Collectors.toMap:

Duplicate key X (attempted merging values y and z)

This change updates IdentifierBindingIndex to ignore collisions. However this
means that colliding resource identifier bindings would be ignored (which is
arguably worse than failing to load the model since it wouldn't ever flag
these issues, and retroactively enforcing things is always challenging).
To address this, I added validation to detect when members with the
resourceIdentifier trait conflict with members of the same binding name
or members that have the same resourceIdentifier trait.
@mtdowling mtdowling requested a review from a team as a code owner October 18, 2022 21:34
@@ -155,25 +152,29 @@ private void processResource(ResourceShape resource, OperationIndex operationInd
}

private boolean isCollection(ResourceShape resource, ToShapeId operationId) {
return resource.getCollectionOperations().contains(operationId)
return resource.getCollectionOperations().contains(operationId.toShapeId())
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I changed this too because this was raising a warning because operationId is a ToShapeId but the set contains ShapeId.

@mtdowling mtdowling merged commit 6cc1ba4 into main Oct 18, 2022
@mtdowling mtdowling deleted the fix-identifier-conflict-bug branch October 24, 2022 16:26
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