Skip to content

Commit

Permalink
fix(go): dependent configSymbol in api client (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit authored Jan 27, 2025
1 parent ed2bba0 commit e1993ed
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import software.amazon.polymorph.smithygo.codegen.GoDelegator;
import software.amazon.polymorph.smithygo.codegen.GoWriter;
import software.amazon.polymorph.smithygo.codegen.SmithyGoDependency;
import software.amazon.polymorph.smithygo.codegen.SymbolUtils;
import software.amazon.polymorph.smithygo.codegen.UnionGenerator;
import software.amazon.polymorph.smithygo.localservice.nameresolver.DafnyNameResolver;
import software.amazon.polymorph.smithygo.localservice.nameresolver.SmithyNameResolver;
Expand All @@ -31,6 +32,7 @@
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ResourceShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.model.traits.UnitTypeTrait;

Expand Down Expand Up @@ -118,7 +120,29 @@ void generateClient(GoWriter writer) {
SmithyNameResolver.smithyTypesNamespace(service)
);
writer.addUseImports(SmithyGoDependency.CONTEXT);

var configShape = configSymbol.expectProperty(
SymbolUtils.SHAPE,
Shape.class
);
if (
!configShape
.toShapeId()
.getNamespace()
.equals(service.toShapeId().getNamespace())
) {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
configShape.toShapeId().getNamespace()
),
SmithyNameResolver.smithyTypesNamespace(configShape)
);
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
configShape.toShapeId().getNamespace()
),
SmithyNameResolver.shapeNamespace(configShape)
);
}
final var dafnyClient = DafnyNameResolver.getDafnyInterfaceClient(service);
writer.write(
"""
Expand All @@ -139,7 +163,7 @@ func NewClient(clientConfig $L) (*$T, error) {
""",
serviceSymbol,
dafnyClient,
SmithyNameResolver.getSmithyType(service, configSymbol),
SmithyNameResolver.getSmithyType(configShape, configSymbol),
serviceSymbol,
SmithyNameResolver.getToDafnyMethodName(
service,
Expand Down

0 comments on commit e1993ed

Please sign in to comment.