From 7afc826602b0c5a0f60732b7fb4d4ff0771d769f Mon Sep 17 00:00:00 2001 From: Luc Talatinian <102624213+lucix-aws@users.noreply.github.com> Date: Fri, 10 May 2024 11:56:23 -0400 Subject: [PATCH] upgrade to smithy 1.49 (#511) --- codegen/gradle.properties | 2 +- .../amazon/smithy/go/codegen/SymbolUtils.java | 4 ++++ .../EndpointClientPluginsGenerator.java | 13 ++--------- .../EndpointParametersGenerator.java | 22 +++++++++---------- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/codegen/gradle.properties b/codegen/gradle.properties index 5de779792..d4081d1c3 100644 --- a/codegen/gradle.properties +++ b/codegen/gradle.properties @@ -1,2 +1,2 @@ -smithyVersion=1.47.0 +smithyVersion=1.49.0 smithyGradleVersion=0.7.0 diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SymbolUtils.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SymbolUtils.java index 1a9fed49c..8313fb66a 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SymbolUtils.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SymbolUtils.java @@ -223,4 +223,8 @@ public static boolean isNilable(Symbol symbol) { || symbol.getProperty(SymbolUtils.GO_SLICE).isPresent() || symbol.getProperty(SymbolUtils.GO_MAP).isPresent(); } + + public static Symbol pointerTo(Symbol symbol) { + return symbol.toBuilder().putProperty(POINTABLE, true).build(); + } } diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java index 5efc73b1d..1d08b6cf3 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java @@ -15,9 +15,10 @@ package software.amazon.smithy.go.codegen.endpoints; +import static software.amazon.smithy.go.codegen.endpoints.EndpointParametersGenerator.parameterAsSymbol; + import java.util.ArrayList; import java.util.List; -import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.go.codegen.GoSettings; import software.amazon.smithy.go.codegen.SymbolUtils; import software.amazon.smithy.go.codegen.integration.ConfigField; @@ -44,16 +45,6 @@ private static String getExportedParameterName(Parameter parameter) { return StringUtils.capitalize(parameter.getName().getName().getValue()); } - private static Symbol parameterAsSymbol(Parameter parameter) { - return switch (parameter.getType()) { - case STRING -> SymbolUtils.createPointableSymbolBuilder("string") - .putProperty(SymbolUtils.GO_UNIVERSE_TYPE, true).build(); - - case BOOLEAN -> SymbolUtils.createPointableSymbolBuilder("bool") - .putProperty(SymbolUtils.GO_UNIVERSE_TYPE, true).build(); - }; - } - @Override public List getClientPlugins() { runtimeClientPlugins.add(RuntimeClientPlugin.builder() diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParametersGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParametersGenerator.java index 3a35f8217..2834cf441 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParametersGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParametersGenerator.java @@ -19,6 +19,7 @@ import static software.amazon.smithy.go.codegen.GoWriter.goBlockTemplate; import static software.amazon.smithy.go.codegen.GoWriter.goDocTemplate; import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; +import static software.amazon.smithy.go.codegen.SymbolUtils.pointerTo; import java.io.Serializable; import java.util.Comparator; @@ -27,7 +28,9 @@ import java.util.Optional; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import software.amazon.smithy.codegen.core.CodegenException; import software.amazon.smithy.codegen.core.Symbol; +import software.amazon.smithy.go.codegen.GoUniverseTypes; import software.amazon.smithy.go.codegen.GoWriter; import software.amazon.smithy.go.codegen.SmithyGoDependency; import software.amazon.smithy.go.codegen.SymbolUtils; @@ -149,12 +152,11 @@ private GoWriter.Writable generateDefaultsMethod(Parameters parameters) { private GoWriter.Writable generateDefaultValue(Parameter parameter, Value defaultValue) { return switch (parameter.getType()) { - case STRING -> goTemplate("$ptrString:T($value:S)", MapUtils.of( - "ptrString", SymbolUtils.createValueSymbolBuilder("String", SmithyGoDependency.SMITHY_PTR).build(), - "value", defaultValue.expectStringValue())); - case BOOLEAN -> goTemplate("$ptrBool:T($value:L)", MapUtils.of( - "ptrBool", SymbolUtils.createValueSymbolBuilder("Bool", SmithyGoDependency.SMITHY_PTR).build(), - "value", defaultValue.expectBooleanValue())); + case STRING -> goTemplate("$T($S)", + SmithyGoDependency.SMITHY_PTR.func("String"), defaultValue.expectStringValue()); + case BOOLEAN -> goTemplate("$T($L)", + SmithyGoDependency.SMITHY_PTR.func("Bool"), defaultValue.expectBooleanValue()); + case STRING_ARRAY -> throw new CodegenException("unsupported endpoint parameter type stringArray"); }; } @@ -197,11 +199,9 @@ private GoWriter.Writable generateValidationMethod(Parameters parameters) { public static Symbol parameterAsSymbol(Parameter parameter) { return switch (parameter.getType()) { - case STRING -> SymbolUtils.createPointableSymbolBuilder("string") - .putProperty(SymbolUtils.GO_UNIVERSE_TYPE, true).build(); - - case BOOLEAN -> SymbolUtils.createPointableSymbolBuilder("bool") - .putProperty(SymbolUtils.GO_UNIVERSE_TYPE, true).build(); + case STRING -> pointerTo(GoUniverseTypes.String); + case BOOLEAN -> pointerTo(GoUniverseTypes.Bool); + case STRING_ARRAY -> throw new CodegenException("unsupported endpoint parameter type stringArray"); }; }