From b04921ef642acbc0d535cd52cf7f2603548d4fcf Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:29:43 +0000 Subject: [PATCH 1/5] Process StaticContextParams with StringArray --- .../codegen/endpointsV2/RuleSetParameterFinder.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java index 93d9d4fb3b9..1850952aa04 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java @@ -18,6 +18,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; +import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.node.NodeVisitor; import software.amazon.smithy.model.node.ObjectNode; @@ -90,6 +92,11 @@ public Map getStaticContextParamValues(OperationShape operation) value = "`" + definition.getValue().expectStringNode().toString() + "`"; } else if (definition.getValue().isBooleanNode()) { value = definition.getValue().expectBooleanNode().toString(); + } else if (definition.getValue().isArrayNode()) { + ArrayNode arrayNode = definition.getValue().expectArrayNode(); + value = arrayNode.getElements().stream() + .map(element -> "'" + element.expectStringNode().getValue() + "'") + .collect(Collectors.joining(", ", "[", "]")); } else { throw new RuntimeException("unexpected type " + definition.getValue().getType().toString() From 7f00d08b7cd570154c14f4fb518c8a6d15f26be3 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:57:58 +0000 Subject: [PATCH 2/5] Process StringArray parameter in ClientContextParams --- .../endpointsV2/RuleSetParameterFinder.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java index 1850952aa04..abedb21f13a 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java @@ -28,6 +28,7 @@ import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.ServiceShape; import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeType; import software.amazon.smithy.rulesengine.traits.ClientContextParamsTrait; import software.amazon.smithy.rulesengine.traits.ContextParamTrait; import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; @@ -68,10 +69,23 @@ public Map getClientContextParams() { if (trait.isPresent()) { ClientContextParamsTrait clientContextParamsTrait = trait.get(); clientContextParamsTrait.getParameters().forEach((name, definition) -> { - map.put( - name, - definition.getType().toString().toLowerCase() // "boolean" and "string" are directly usable in TS. - ); + ShapeType shapeType = definition.getType(); + if (shapeType.isShapeType(ShapeType.STRING) || shapeType.isShapeType(ShapeType.BOOLEAN)) { + map.put( + name, + // "boolean" and "string" are directly usable in TS. + definition.getType().toString().toLowerCase() + ); + } else if (shapeType.isShapeType(ShapeType.LIST)) { + map.put( + name, + "string[]" // Only string lists are supported. + ); + } else { + throw new RuntimeException("unexpected type " + + definition.getType().toString() + + " received as clientContextParam."); + } }); } return map; From 74f79e67212a9a845fe58acbb1ce74e07aeb5e5e Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:19:57 +0000 Subject: [PATCH 3/5] Process StringArray in ParameterGenerator --- .../codegen/endpointsV2/ParameterGenerator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 88cf56867ff..45d176ec6a0 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 @@ -18,6 +18,7 @@ import java.util.AbstractMap; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import software.amazon.smithy.model.node.BooleanNode; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.node.ObjectNode; @@ -64,6 +65,10 @@ public ParameterGenerator(String key, Node param, boolean isInputKey) { case "boolean": tsParamType = "boolean"; break; + case "StringArray": + case "stringArray": + tsParamType = "string[]"; + break; default: // required by linter } @@ -102,6 +107,12 @@ public String defaultAsCodeString() { case "boolean": buffer += paramNode.expectBooleanMember("default").getValue() ? "true" : "false"; break; + case "StringArray": + case "stringArray": + buffer += paramNode.expectArrayMember("default").getElements().stream() + .map(element -> "'" + element.expectStringNode().getValue() + "'") + .collect(Collectors.joining(", ", "[", "]")); + break; default: throw new RuntimeException("Unhandled endpoint param type: " + type.getValue()); } From c62112d23e770d152af6b98f77e7f53c62865910 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:00:35 +0000 Subject: [PATCH 4/5] Remove redundant value StringArray from switch case --- .../typescript/codegen/endpointsV2/ParameterGenerator.java | 2 -- 1 file changed, 2 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 45d176ec6a0..6568478572a 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 @@ -65,7 +65,6 @@ public ParameterGenerator(String key, Node param, boolean isInputKey) { case "boolean": tsParamType = "boolean"; break; - case "StringArray": case "stringArray": tsParamType = "string[]"; break; @@ -107,7 +106,6 @@ public String defaultAsCodeString() { case "boolean": buffer += paramNode.expectBooleanMember("default").getValue() ? "true" : "false"; break; - case "StringArray": case "stringArray": buffer += paramNode.expectArrayMember("default").getElements().stream() .map(element -> "'" + element.expectStringNode().getValue() + "'") From 6b76dc93f65f7966c9ff8cdc94bf0b8e5a372790 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:24:37 +0000 Subject: [PATCH 5/5] Used escape quotes for String Array values --- .../typescript/codegen/endpointsV2/ParameterGenerator.java | 4 ++-- .../codegen/endpointsV2/RuleSetParameterFinder.java | 4 ++-- 2 files changed, 4 insertions(+), 4 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 6568478572a..fd02400d491 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 @@ -108,8 +108,8 @@ public String defaultAsCodeString() { break; case "stringArray": buffer += paramNode.expectArrayMember("default").getElements().stream() - .map(element -> "'" + element.expectStringNode().getValue() + "'") - .collect(Collectors.joining(", ", "[", "]")); + .map(element -> element.expectStringNode().getValue()) + .collect(Collectors.joining("`, `", "[`", "`]")); break; default: throw new RuntimeException("Unhandled endpoint param type: " + type.getValue()); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java index abedb21f13a..26b00c8cd6d 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java @@ -109,8 +109,8 @@ public Map getStaticContextParamValues(OperationShape operation) } else if (definition.getValue().isArrayNode()) { ArrayNode arrayNode = definition.getValue().expectArrayNode(); value = arrayNode.getElements().stream() - .map(element -> "'" + element.expectStringNode().getValue() + "'") - .collect(Collectors.joining(", ", "[", "]")); + .map(element -> element.expectStringNode().getValue()) + .collect(Collectors.joining("`, `", "[`", "`]")); } else { throw new RuntimeException("unexpected type " + definition.getValue().getType().toString()