From 9315ba774c9a0a5c2238b306519afb31ddde0ae4 Mon Sep 17 00:00:00 2001 From: skotambkar Date: Fri, 30 Apr 2021 00:48:14 -0700 Subject: [PATCH] update for java idiomatic style, and update smithy-go version --- .../smithy/go/codegen/SmithyGoDependency.java | 2 +- .../integration/DocumentShapeSerVisitor.java | 13 ++++--- .../HttpBindingProtocolGenerator.java | 34 +++++++------------ 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SmithyGoDependency.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SmithyGoDependency.java index 3888e37d9..60a628789 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SmithyGoDependency.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SmithyGoDependency.java @@ -118,7 +118,7 @@ private static GoDependency relativePackage( private static final class Versions { private static final String GO_STDLIB = "1.15"; private static final String GO_CMP = "v0.5.4"; - private static final String SMITHY_GO = "v1.3.1"; + private static final String SMITHY_GO = "v1.3.2-0.20210427182611-342f8a297d6e"; private static final String GO_JMESPATH = "v0.4.0"; } } diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/DocumentShapeSerVisitor.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/DocumentShapeSerVisitor.java index b55ea5cf2..f95d3afa2 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/DocumentShapeSerVisitor.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/DocumentShapeSerVisitor.java @@ -325,11 +325,14 @@ private void generateSerFunction( Symbol symbol = symbolProvider.toSymbol(shape); - String functionName = shape.hasTrait(SyntheticClone.class) - ? ProtocolGenerator.getOperationDocumentSerFuncName( - shape, context.getProtocolName()) - : ProtocolGenerator.getDocumentSerializerFunctionName( - shape, context.getService(), context.getProtocolName()); + String functionName; + if (shape.hasTrait(SyntheticClone.class)) { + functionName = ProtocolGenerator.getOperationDocumentSerFuncName( + shape, context.getProtocolName()); + } else { + functionName = ProtocolGenerator.getDocumentSerializerFunctionName( + shape, context.getService(), context.getProtocolName()); + } String additionalArguments = getAdditionalSerArguments().entrySet().stream() .map(entry -> String.format(", %s %s", entry.getKey(), entry.getValue())) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java index 09e9a4094..9d09afd7f 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java @@ -666,14 +666,14 @@ private void writeHttpBindingSetter( } private void writeHttpBindingMember( - final GenerationContext context, + GenerationContext context, HttpBinding binding ) { GoWriter writer = context.getWriter(); Model model = context.getModel(); MemberShape memberShape = binding.getMember(); - final Shape targetShape = model.expectShape(memberShape.getTarget()); - final HttpBinding.Location location = binding.getLocation(); + Shape targetShape = model.expectShape(memberShape.getTarget()); + HttpBinding.Location location = binding.getLocation(); // return an error if member shape targets location label, but is unset. if (location.equals(HttpBinding.Location.LABEL)) { @@ -782,28 +782,18 @@ private void writeQueryBinding( .getMember(); writer.openBlock("for i := range $L {", "}", operand, () -> { GoValueAccessUtils.writeIfZeroValue(context.getModel(), writer, collectionMember, - operand + "[i]", () -> { - writer.write("continue"); - }); + operand + "[i]", () -> writer.write("continue")); + + String addQuery = String.format("$L.AddQuery(%s).$L", isQueryParams ? "$L" : "$S"); writeHttpBindingSetter(context, writer, collectionMember, location, operand + "[i]", - (w, s) -> { - if (isQueryParams) { - w.writeInline("$L.AddQuery($L).$L", dest, locationName, s); - } else { - w.writeInline("$L.AddQuery($S).$L", dest, locationName, s); - } - }); + (w, s) -> w.writeInline(addQuery, dest, locationName, s)); }); - } else { - writeHttpBindingSetter(context, writer, memberShape, location, operand, - (w, s) -> { - if (isQueryParams) { - w.writeInline("$L.SetQuery($L).$L", dest, locationName, s); - } else { - w.writeInline("$L.SetQuery($S).$L", dest, locationName, s); - } - }); + return; } + + String setQuery = String.format("$L.SetQuery(%s).$L", isQueryParams ? "$L" : "$S"); + writeHttpBindingSetter(context, writer, memberShape, location, operand, + (w, s) -> w.writeInline(setQuery, dest, locationName, s)); } private void writeHeaderBinding(