Skip to content

Commit

Permalink
fix(go): AWS SDK shape namespace (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit authored Jan 29, 2025
1 parent e1993ed commit edf861c
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public void renderStructure(Runnable runnable, boolean isInputStructure) {
.getProperty(SymbolUtils.INPUT_VARIANT, Symbol.class)
.orElse(memberSymbol);
}
var namespace = SmithyNameResolver.smithyTypesNamespace(targetShape);
var namespace = SmithyNameResolver.smithyTypesNamespace(
targetShape,
model
);

if (targetShape.hasTrait(ReferenceTrait.class)) {
memberSymbol =
Expand Down Expand Up @@ -158,7 +161,7 @@ public void renderStructure(Runnable runnable, boolean isInputStructure) {
targetShape.getId().getNamespace()
),
"types",
SmithyNameResolver.smithyTypesNamespace(targetShape)
SmithyNameResolver.smithyTypesNamespace(targetShape, model)
);
} else if (
!member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,10 @@ public Symbol mapShape(MapShape shape) {

private Symbol.Builder symbolBuilderFor(Shape shape, String typeName) {
final String namespace;
if (shape.hasTrait(ServiceTrait.class)) {
namespace =
shape.expectTrait(ServiceTrait.class).getSdkId().toLowerCase();
if (SmithyNameResolver.isShapeFromAWSSDK(shape)) {
namespace = SmithyNameResolver.smithyTypesNamespace(shape, model);
} else {
namespace = SmithyNameResolver.smithyTypesNamespace(shape);
namespace = SmithyNameResolver.smithyTypesNamespace(shape, model);
}
if (pointableIndex.isPointable(shape)) {
return SymbolUtils.createPointableSymbolBuilder(
Expand Down Expand Up @@ -541,11 +540,11 @@ public Symbol stringShape(StringShape shape) {
return symbolBuilderFor(
shape,
name,
SmithyNameResolver.smithyTypesNamespace(shape)
SmithyNameResolver.smithyTypesNamespace(shape, model)
)
.definitionFile(
"./%s/enums.go".formatted(
SmithyNameResolver.smithyTypesNamespace(shape)
SmithyNameResolver.smithyTypesNamespace(shape, model)
)
)
.build();
Expand Down Expand Up @@ -576,13 +575,13 @@ public Symbol structureShape(StructureShape shape) {
if (shape.hasTrait(ErrorTrait.ID)) {
builder.definitionFile(
"./%s/errors.go".formatted(
SmithyNameResolver.smithyTypesNamespace(shape)
SmithyNameResolver.smithyTypesNamespace(shape, model)
)
);
} else {
builder.definitionFile(
"./%s/types.go".formatted(
SmithyNameResolver.smithyTypesNamespace(shape)
SmithyNameResolver.smithyTypesNamespace(shape, model)
)
);
}
Expand Down Expand Up @@ -646,7 +645,7 @@ public Symbol unionShape(UnionShape shape) {
return symbolBuilderFor(
shape,
name,
SmithyNameResolver.smithyTypesNamespace(shape)
SmithyNameResolver.smithyTypesNamespace(shape, model)
)
.definitionFile("./types/types.go")
.build();
Expand All @@ -672,11 +671,11 @@ public Symbol intEnumShape(IntEnumShape shape) {
return symbolBuilderFor(
shape,
name,
SmithyNameResolver.smithyTypesNamespace(settings.getService(model))
SmithyNameResolver.smithyTypesNamespace(settings.getService(model), model)
)
.definitionFile(
"./%s/enums.go".formatted(
SmithyNameResolver.smithyTypesNamespace(shape)
SmithyNameResolver.smithyTypesNamespace(shape, model)
)
)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public void generateUnion(GoWriter writer) {
writer.write("Value $T", memberSymbol);
} else {
// Handling smithy-dafny Reference Trait begins
var namespace = SmithyNameResolver.smithyTypesNamespace(target);
var namespace = SmithyNameResolver.smithyTypesNamespace(
target,
model
);
var newMemberSymbol = memberSymbol;
if (target.hasTrait(ReferenceTrait.class)) {
newMemberSymbol =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ private void renderListShape(
);
final var inputType = GoCodegenUtils.getType(
symbolProvider.toSymbol(currentShape),
isExternalShape
isExternalShape,
context.model()
);
if (isExternalShape) {
if (SmithyNameResolver.isShapeFromAWSSDK(currentShape)) {
Expand All @@ -523,14 +524,14 @@ private void renderListShape(
currentShape.getId().getNamespace()
),
"types",
SmithyNameResolver.smithyTypesNamespace(currentShape)
SmithyNameResolver.smithyTypesNamespace(currentShape, model)
);
} else {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
currentShape.getId().getNamespace()
),
SmithyNameResolver.smithyTypesNamespace(currentShape)
SmithyNameResolver.smithyTypesNamespace(currentShape, model)
);
}
}
Expand Down Expand Up @@ -610,7 +611,8 @@ private void renderMapShape(
);
final var inputType = GoCodegenUtils.getType(
symbolProvider.toSymbol(currentShape),
isExternalShape
isExternalShape,
context.model()
);
if (isExternalShape) {
if (SmithyNameResolver.isShapeFromAWSSDK(currentShape)) {
Expand All @@ -619,14 +621,14 @@ private void renderMapShape(
currentShape.getId().getNamespace()
),
"types",
SmithyNameResolver.smithyTypesNamespace(currentShape)
SmithyNameResolver.smithyTypesNamespace(currentShape, model)
);
} else {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
currentShape.getId().getNamespace()
),
SmithyNameResolver.smithyTypesNamespace(currentShape)
SmithyNameResolver.smithyTypesNamespace(currentShape, model)
);
}
}
Expand Down Expand Up @@ -671,18 +673,21 @@ private void renderUnionShape(
var dataSourceForUnion = dataSource;
final var currServiceShapeNamespace =
SmithyNameResolver.smithyTypesNamespace(
context.settings().getService(model)
context.settings().getService(model),
model
);
final var currShapeNamespace = SmithyNameResolver.smithyTypesNamespace(
model.expectShape(memberShape.getTarget())
model.expectShape(memberShape.getTarget()),
model
);
if (!funcInput.isEmpty()) {
final Boolean isExternalShape =
!currServiceShapeNamespace.equals(currShapeNamespace) &&
!currShapeNamespace.startsWith("smithy");
final var inputType = GoCodegenUtils.getType(
symbolProvider.toSymbol(currentShape),
isExternalShape
isExternalShape,
context.model()
);
if (isExternalShape) {
if (SmithyNameResolver.isShapeFromAWSSDK(currentShape)) {
Expand All @@ -691,14 +696,14 @@ private void renderUnionShape(
currentShape.getId().getNamespace()
),
"types",
SmithyNameResolver.smithyTypesNamespace(currentShape)
SmithyNameResolver.smithyTypesNamespace(currentShape, model)
);
} else {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
currentShape.getId().getNamespace()
),
SmithyNameResolver.smithyTypesNamespace(currentShape)
SmithyNameResolver.smithyTypesNamespace(currentShape, model)
);
}
}
Expand All @@ -721,7 +726,8 @@ private void renderUnionShape(
);
for (final var memberInUnion : currentShape.getAllMembers().values()) {
final var currMemberNamespace = SmithyNameResolver.smithyTypesNamespace(
currentShape
currentShape,
model
);
final Boolean isExternalShape =
!currServiceShapeNamespace.equals(currMemberNamespace) &&
Expand Down
Loading

0 comments on commit edf861c

Please sign in to comment.