From 8a7d9fee7ee35eb6ee669d0827c68256bf197940 Mon Sep 17 00:00:00 2001 From: Rishav karanjit Date: Mon, 9 Dec 2024 15:58:15 -0800 Subject: [PATCH] fix(Go): fix missing imports (#739) * auto commit * auto commit * auto commit --------- Co-authored-by: Shubham Chaturvedi --- ...fnyLocalServiceTypeConversionProtocol.java | 18 ++++++++++++++++++ .../DafnyToSmithyShapeVisitor.java | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/DafnyLocalServiceTypeConversionProtocol.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/DafnyLocalServiceTypeConversionProtocol.java index 793379896..6de82bac7 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/DafnyLocalServiceTypeConversionProtocol.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/DafnyLocalServiceTypeConversionProtocol.java @@ -1216,6 +1216,18 @@ private void handleDepErrorSerializer( ) ); } else { + w.addImportFromModule( + SmithyNameResolver.getGoModuleNameForSmithyNamespace( + depShape.toShapeId().getNamespace() + ), + SmithyNameResolver.smithyTypesNamespace(depShape) + ); + w.addImportFromModule( + SmithyNameResolver.getGoModuleNameForSmithyNamespace( + depShape.toShapeId().getNamespace() + ), + SmithyNameResolver.shapeNamespace(depShape) + ); w.write( """ case $L.$LBaseException: @@ -1487,6 +1499,12 @@ func Error_FromDafny(err $L.Error)(error) { final var depService = context .model() .expectShape(dep, ServiceShape.class); + writer.addImportFromModule( + SmithyNameResolver.getGoModuleNameForSmithyNamespace( + depService.toShapeId().getNamespace() + ), + SmithyNameResolver.shapeNamespace(depService) + ); w.write( """ if err.Is_$L() { diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/shapevisitor/DafnyToSmithyShapeVisitor.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/shapevisitor/DafnyToSmithyShapeVisitor.java index a514abfdc..c853ee671 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/shapevisitor/DafnyToSmithyShapeVisitor.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/shapevisitor/DafnyToSmithyShapeVisitor.java @@ -231,6 +231,12 @@ private String referencedResourceShape(final Shape resourceOrService) { ), SmithyNameResolver.shapeNamespace(resourceShape) ); + writer.addImportFromModule( + SmithyNameResolver.getGoModuleNameForSmithyNamespace( + resourceOrService.toShapeId().getNamespace() + ), + SmithyNameResolver.smithyTypesNamespace(resourceShape) + ); namespace = SmithyNameResolver.shapeNamespace(resourceOrService).concat("."); } @@ -582,6 +588,19 @@ public String stringShape(final StringShape shape) { ); } if (shape.hasTrait(EnumTrait.class)) { + if ( + !shape + .toShapeId() + .getNamespace() + .equals(context.settings().getService().getNamespace()) + ) { + writer.addImportFromModule( + SmithyNameResolver.getGoModuleNameForSmithyNamespace( + shape.toShapeId().getNamespace() + ), + DafnyNameResolver.dafnyTypesNamespace(shape) + ); + } if (this.isOptional) { return """ return func () *%s.%s {