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(go): AWS SDK shape namespace #769

Merged
merged 13 commits into from
Jan 29, 2025
Merged

Conversation

rishav-karanjit
Copy link
Member

@rishav-karanjit rishav-karanjit commented Jan 22, 2025

Issue #, if available:

Description of changes:
Short description:

  • return <serviceName> if shape in aws sdk models is inside input and output of operation
  • add new parameter model to the smithyTypeNamespace function

Long description:
All the shape which is input and output of operation is inside github.com/aws/aws-sdk-go-v2/service/dynamodb and all other inside those are in github.com/aws/aws-sdk-go-v2/service/dynamodb/types. However, in current main-1.x, smithyNameResolver return <serviceName>types (example: dynamodbtypes and kmstypes) in every scenario which is wrong. Updates from this PR loops in the model's operation shape and if the shape belong to input/output of the operation shape and uses either types or module for the shapes.

Note: We alias service/types module to types. For example: github.com/aws/aws-sdk-go-v2/service/dynamodb/types is aliased into dynamodbtypes and github.com/aws/aws-sdk-go-v2/service/kms/types into kmstypes so that there won't be name collision.

Test PR in MPL after bumping smithy-dafny to this branch: aws/aws-cryptographic-material-providers-library#1243
(No polymorph changes expected in MPL because none of the model in MPL depends on shape that are inside input and output of operation shape.)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rishav-karanjit rishav-karanjit changed the title fix aws sdk shape namespace fix(go): AWS SDK shape namespace Jan 22, 2025
@rishav-karanjit rishav-karanjit marked this pull request as ready for review January 22, 2025 22:42
@rishav-karanjit rishav-karanjit requested a review from a team as a code owner January 22, 2025 22:42
Comment on lines +78 to +85
// Boolean to hold if shape is input or output of any operation
boolean isTopLevelShape = model
.shapes(OperationShape.class)
.anyMatch(op ->
op.getInput().filter(shape.getId()::equals).isPresent() ||
op.getOutput().filter(shape.getId()::equals).isPresent()
);
return isTopLevelShape ? sdkName : sdkName.concat("types");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not overload the method and pass this boolean only when required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because if we do that every time we call smithyTypesNamespace we will end-up doing a if-else check like below:

if (isShapeFromAWSSDK(shape)) {
    smithyTypesNamespace(..., boolean flag);
} else {
    smithyTypesNamespace(...);
}

@rishav-karanjit rishav-karanjit merged commit edf861c into main-1.x Jan 29, 2025
86 checks passed
@rishav-karanjit rishav-karanjit deleted the rishav/go/fixawssdkshape branch January 29, 2025 16:51
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