-
Notifications
You must be signed in to change notification settings - Fork 8
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: codegen changes for calling aws sdk from local service #538
fix: codegen changes for calling aws sdk from local service #538
Conversation
This reverts commit 72b4384.
|
||
# Go | ||
|
||
GO_DEPENDENCY_MODULE_NAMES := \ | ||
--dependency-library-name=com.amazonaws.kms=github.com/smithy-lang/smithy-dafny/kmsv2 \ | ||
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2 | ||
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2 \ | ||
--dependency-library-name=sdk.com.amazonaws.dynamodb=github.com/aws/aws-sdk-go-v2/service/dynamodb \ |
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.
I need this to import kms or dynamodb and make client in native side
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.
What would happen if the namespace for our model and the sdk collides?
@@ -45,10 +49,47 @@ structure CallDDBScanInput { | |||
} | |||
|
|||
structure CallDDBScanOutput { | |||
@required |
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.
Removing required because I will have to return a value if its required. Also, having a check expect itemOutput.Value.Some?
makes more sense
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.
Why not return 0
since this is an Integer?
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.
If I return 0 and if DDB has 0 item, the success case will have false failure.
conditionExpression: com.amazonaws.dynamodb#ConditionExpression | ||
} | ||
|
||
structure CallDDBPutItemOutput { |
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.
There is nothing I could return from PutItem
call. So, this is empty.
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.
PutItemOutput.Attributes
will return empty unless putitem has overridden a item
@@ -1,56 +0,0 @@ | |||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
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.
Unlike what git diff shows. This is renaming file. Not removing it.
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.
This file is also a file name renaming change not deleting it.
@@ -806,7 +814,8 @@ private void generateSerializerFunctions( | |||
); | |||
var inputType = GoCodegenUtils.getType( | |||
context.symbolProvider().toSymbol(visitingShape), | |||
serviceShape.expectTrait(ServiceTrait.class) | |||
serviceShape.expectTrait(ServiceTrait.class), | |||
true |
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.
GoCodegenUtils.getType has now an update so that we can say to include namespace in the types or not. Previously, this boolean was not there so this is updated.
@@ -689,6 +689,8 @@ private class GoSymbolFormatter | |||
public String apply(Object type, String indent) { | |||
if (type instanceof Symbol) { | |||
Symbol resolvedSymbol = (Symbol) type; | |||
// get symbol name for literal | |||
// Note: This literal could be changed in upcoming codes in this if block |
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.
Just some comments because I got confused read this codes.
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.
I don't see any change in the literal though? Aren't we required to change this to use map[string][ddbtypes.AttributeValue]
?
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.
.build() | ||
); | ||
} else { | ||
builder.putProperty( | ||
"Referred", | ||
symbolBuilderFor( | ||
referredShape, | ||
"I".concat(getDefaultShapeName(referredShape)) |
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.
We have reversed the if else loop. So, this is in diff.
var inputType = GoCodegenUtils.getType( | ||
symbolProvider.toSymbol(currentShape), | ||
currentShape | ||
currentShape, | ||
isExternalShape |
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.
If external shape then include namespace or else don't include
@@ -60,9 +62,14 @@ public static String shapeNamespace(final Shape shape) { | |||
} | |||
|
|||
public static String smithyTypesNamespace(final Shape shape) { |
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.
The type namespace for service should be "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" (or KMS one) but there can be multiple service in a model and this will cause confusion between kms and ddb. So, I have decided to make it kmstypes or dynamodbtypes.
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.
Yes - we always need to alias it.
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.
Some suggestions / clarifications below, otherwise LGTM.
@@ -45,10 +49,47 @@ structure CallDDBScanInput { | |||
} | |||
|
|||
structure CallDDBScanOutput { | |||
@required |
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.
Why not return 0
since this is an Integer?
|
||
# Go | ||
|
||
GO_DEPENDENCY_MODULE_NAMES := \ | ||
--dependency-library-name=com.amazonaws.kms=github.com/smithy-lang/smithy-dafny/kmsv2 \ | ||
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2 | ||
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2 \ | ||
--dependency-library-name=sdk.com.amazonaws.dynamodb=github.com/aws/aws-sdk-go-v2/service/dynamodb \ |
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.
What would happen if the namespace for our model and the sdk collides?
@@ -689,6 +689,8 @@ private class GoSymbolFormatter | |||
public String apply(Object type, String indent) { | |||
if (type instanceof Symbol) { | |||
Symbol resolvedSymbol = (Symbol) type; | |||
// get symbol name for literal | |||
// Note: This literal could be changed in upcoming codes in this if block |
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.
I don't see any change in the literal though? Aren't we required to change this to use map[string][ddbtypes.AttributeValue]
?
if (shape.hasTrait(ServiceTrait.class)) { | ||
namespace = | ||
shape.expectTrait(ServiceTrait.class).getSdkId().toLowerCase(); |
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.
Ahh so this is where the map
case get handled as well.
if (isExternalShape) { | ||
if (SmithyNameResolver.isShapeFromAWSSDK(currentShape)) { | ||
writer.addImportFromModule( | ||
SmithyNameResolver.getGoModuleNameForSdkNamespace( | ||
currentShape.getId().getNamespace() | ||
), | ||
"types", | ||
SmithyNameResolver.smithyTypesNamespace(currentShape) | ||
); | ||
} else { | ||
writer.addImportFromModule( | ||
SmithyNameResolver.getGoModuleNameForSmithyNamespace( | ||
currentShape.getId().getNamespace() | ||
), | ||
SmithyNameResolver.smithyTypesNamespace(currentShape) | ||
); | ||
} | ||
} |
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.
Suggestion: This could be moved inside the SmithyNameResolver.
@@ -60,9 +62,14 @@ public static String shapeNamespace(final Shape shape) { | |||
} | |||
|
|||
public static String smithyTypesNamespace(final Shape shape) { |
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.
Yes - we always need to alias it.
if (SmithyNameResolver.isShapeFromAWSSDK(shape)) { | ||
writer.addImportFromModule( | ||
SmithyNameResolver.getGoModuleNameForSdkNamespace( | ||
shape.getId().getNamespace() | ||
), | ||
"types", | ||
SmithyNameResolver.smithyTypesNamespace(shape) | ||
); | ||
} |
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.
Same, all this can be moved inside the NameResolver and we can then avoid this repetition.
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.
Let's do it in next PR once positional is merged.
02579d9
into
rishav-awssdkFromLocal-Testmodel
Issue #, if available:
Description of changes:
smithy-dafny-codegen-cli workflows / gradle-build-smithy-dafny (macos-12) (pull_request)
because this will be fixed from mainBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.