From 8e23b1b1df60d81ae58a93998228a8a60a72cc93 Mon Sep 17 00:00:00 2001 From: George Fu Date: Fri, 8 Sep 2023 15:19:53 -0400 Subject: [PATCH] fix: allow lowercase endpoint param (#923) --- .../endpointsV2/ParameterGenerator.java | 18 ++++++++++++++++-- .../endpointsV2/RuleSetParametersVisitor.java | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java index 3bb10554e00..88cf56867ff 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java @@ -30,11 +30,21 @@ public class ParameterGenerator { private final String parameterName; private final Node param; private boolean required = false; + private boolean isInputKey; private String tsParamType = "string"; - public ParameterGenerator(String key, Node param) { + /** + * @param key - the param name. + * @param param - the param value. + * @param isInputKey - whether the key is a client input key. This is + * distinct from canonical endpoint param name + * because it has been transformed to match + * pre-existing keys in published clients. + */ + public ParameterGenerator(String key, Node param, boolean isInputKey) { parameterName = key; this.param = param; + this.isInputKey = isInputKey; ObjectNode paramNode = param.asObjectNode() .orElseThrow(() -> new RuntimeException("param node is not object node.")); @@ -60,6 +70,10 @@ public ParameterGenerator(String key, Node param) { } } + public ParameterGenerator(String key, Node param) { + this(key, param, false); + } + public boolean isBuiltIn() { return param.expectObjectNode().containsMember("builtIn"); } @@ -114,7 +128,7 @@ public String toCodeString(boolean isClientContextParam) { } buffer += ": "; - if (parameterName.equals("endpoint")) { + if (parameterName.equals("endpoint") && isInputKey) { buffer += "string | Provider | Endpoint | Provider | EndpointV2 | Provider;"; } else { if (isClientContextParam) { diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java index 67fdc2ae470..f3bef984b67 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java @@ -63,7 +63,7 @@ public Void objectNode(ObjectNode node) { localKey = EndpointsParamNameMap.getLocalName(key); } - ParameterGenerator parameterGenerator = new ParameterGenerator(localKey, param); + ParameterGenerator parameterGenerator = new ParameterGenerator(localKey, param, useLocalNames); if (localKey.equals("endpoint")) { writer.addImport("Endpoint", null, TypeScriptDependency.SMITHY_TYPES);