From e18086e0d9844b15d7018b2a329e6ec96a5c7660 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:49:20 +0000 Subject: [PATCH 01/13] Process OperationContextParams in RuleSetParameterFinder --- .../endpointsV2/RuleSetParameterFinder.java | 49 +++++++++++++++++++ 1 file changed, 49 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 26b00c8cd6d..cfaaff9a27a 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 @@ -32,6 +32,7 @@ import software.amazon.smithy.rulesengine.traits.ClientContextParamsTrait; import software.amazon.smithy.rulesengine.traits.ContextParamTrait; import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; +import software.amazon.smithy.rulesengine.traits.OperationContextParamsTrait; import software.amazon.smithy.rulesengine.traits.StaticContextParamsTrait; import software.amazon.smithy.utils.SmithyInternalApi; @@ -152,6 +153,54 @@ public Map getContextParams(Shape operationInput) { return map; } + /** + * Get map of params to JavaScript equivalent of provided JMESPath expressions. + */ + public Map getOperationContextParamValues(Shape operationInput) { + Map map = new HashMap<>(); + + Optional trait = operationInput.getTrait(OperationContextParamsTrait.class); + if (trait.isPresent()) { + OperationContextParamsTrait operationContextParamsTrait = trait.get(); + operationContextParamsTrait.getParameters().forEach((name, definition) -> { + String separator = "."; + String value = "this" + separator + "input"; + String path = definition.getPath(); + + // Split JMESPath expression string on separator and add JavaScript equivalent. + for (String part : path.split("[" + separator + "]")) { + // Process keys https://jmespath.org/specification.html#keys + if (part.startsWith("keys(")) { + // Get provided object for which keys are to be extracted. + String object = part.substring(5, part.length() - 1); + value = "Object.keys(" + value + separator + object + ")"; + continue; + } + + // Process list wildcard expression https://jmespath.org/specification.html#wildcard-expressions + if (part.equals("*") || part.equals("[*]")) { + value = "Object.values(" + value + ")"; + continue; + } + + // Process hash wildcard expression https://jmespath.org/specification.html#wildcard-expressions + if (part.endsWith("[*]")) { + // Get key to run hash wildcard on. + String key = part.substring(0, part.length() - 3); + value = "Object.values(" + value + separator + key + ")"; + continue; + } + + // Treat remaining part as identifier without spaces https://jmespath.org/specification.html#identifiers + value += separator + part; + } + + }); + } + + return map; + } + private static class RuleSetParameterFinderVisitor extends NodeVisitor.Default { private final Map map; From e8e2efb3cece8d695d8a0cbee3578fdee293bc19 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:59:11 +0000 Subject: [PATCH 02/13] Populate Operation Context Params in Endpoint Instruction Provider --- .../amazon/smithy/typescript/codegen/CommandGenerator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index babd90a12a0..af5ac63a2bb 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -299,6 +299,12 @@ private void generateEndpointParameterInstructionProvider() { } paramNames.add(name); }); + + parameterFinder.getOperationContextParamValues(operationInput).forEach((name, jmesPathForInputInJs) -> { + writer.write( + "$L: { type: \"operationContextParams\", name: $L },", + name, jmesPathForInputInJs); + }); } writer.write("})") .dedent(); From 0d5f950ce46c8ef019aacbd4381793575116d3fc Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:08:17 +0000 Subject: [PATCH 03/13] Use text-block for operation context param values --- .../amazon/smithy/typescript/codegen/CommandGenerator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index af5ac63a2bb..9e79dce5684 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -302,8 +302,10 @@ private void generateEndpointParameterInstructionProvider() { parameterFinder.getOperationContextParamValues(operationInput).forEach((name, jmesPathForInputInJs) -> { writer.write( - "$L: { type: \"operationContextParams\", name: $L },", - name, jmesPathForInputInJs); + """ + $L: { type: \"operationContextParams\", name: $L }, + """, + name, jmesPathForInputInJs); }); } writer.write("})") From fdcb5656d9334ecec608ef547eca951f9ee3dc03 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:55:09 +0000 Subject: [PATCH 04/13] Populate name and value when processing Operation Context Params --- .../typescript/codegen/endpointsV2/RuleSetParameterFinder.java | 1 + 1 file changed, 1 insertion(+) 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 cfaaff9a27a..56384dd52f1 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 @@ -195,6 +195,7 @@ public Map getOperationContextParamValues(Shape operationInput) value += separator + part; } + map.put(name, value); }); } From bb72d3a006c60f6808354e63ebc809009169aa1a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:04:30 +0000 Subject: [PATCH 05/13] Search for Operation Context Params trait on OperationShape --- .../amazon/smithy/typescript/codegen/CommandGenerator.java | 2 +- .../codegen/endpointsV2/RuleSetParameterFinder.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index 9e79dce5684..4eb9ca83a2c 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -300,7 +300,7 @@ private void generateEndpointParameterInstructionProvider() { paramNames.add(name); }); - parameterFinder.getOperationContextParamValues(operationInput).forEach((name, jmesPathForInputInJs) -> { + parameterFinder.getOperationContextParamValues(operation).forEach((name, jmesPathForInputInJs) -> { writer.write( """ $L: { type: \"operationContextParams\", name: $L }, 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 56384dd52f1..a821ba2f013 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 @@ -156,10 +156,10 @@ public Map getContextParams(Shape operationInput) { /** * Get map of params to JavaScript equivalent of provided JMESPath expressions. */ - public Map getOperationContextParamValues(Shape operationInput) { + public Map getOperationContextParamValues(OperationShape operation) { Map map = new HashMap<>(); - Optional trait = operationInput.getTrait(OperationContextParamsTrait.class); + Optional trait = operation.getTrait(OperationContextParamsTrait.class); if (trait.isPresent()) { OperationContextParamsTrait operationContextParamsTrait = trait.get(); operationContextParamsTrait.getParameters().forEach((name, definition) -> { From f0221019a66e7931efa9df77368adcfa6d1fc5df Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:25:22 +0000 Subject: [PATCH 06/13] Add tests for Operation Context Params Identifier and SubExpression --- .../codegen/CommandGeneratorTest.java | 48 ++++++++++++------- .../endpoints-operation-context-params.smithy | 44 +++++++++++++++++ 2 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java index 7b4e3ae6d4f..e7dc383f3d7 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java @@ -14,7 +14,7 @@ public class CommandGeneratorTest { public void addsCommandSpecificPlugins() { testCommmandCodegen( "output-structure.smithy", - "getSerdePlugin(config, this.serialize, this.deserialize)" + new String[] {"getSerdePlugin(config, this.serialize, this.deserialize)"} ); } @@ -22,7 +22,7 @@ public void addsCommandSpecificPlugins() { public void writesSerializer() { testCommmandCodegen( "output-structure.smithy", - ".ser(" + new String[] {".ser("} ); } @@ -30,30 +30,44 @@ public void writesSerializer() { public void writesDeserializer() { testCommmandCodegen( "output-structure.smithy", - ".de(" + new String[] {".de("} ); } - private void testCommmandCodegen(String file, String expectedType) { - Model model = Model.assembler() - .addImport(getClass().getResource(file)) - .assemble() - .unwrap(); + @Test + public void writesOperationContextParamValues() { + testCommmandCodegen( + "endpointsV2/endpoints-operation-context-params.smithy", + new String[] { + "opContextParamIdentifier: { type: \"operationContextParams\", name: this.input.fooString }", + "opContextParamSubExpression: { type: \"operationContextParams\", name: this.input.fooObj.bar }", + } + ); + } + + private void testCommmandCodegen(String filename, String[] expectedTypeArray) { MockManifest manifest = new MockManifest(); PluginContext context = PluginContext.builder() - .model(model) - .fileManifest(manifest) - .settings(Node.objectNodeBuilder() - .withMember("service", Node.from("smithy.example#Example")) - .withMember("package", Node.from("example")) - .withMember("packageVersion", Node.from("1.0.0")) - .build()) - .build(); + .pluginClassLoader(getClass().getClassLoader()) + .model(Model.assembler() + .addImport(getClass().getResource(filename)) + .discoverModels() + .assemble() + .unwrap()) + .fileManifest(manifest) + .settings(Node.objectNodeBuilder() + .withMember("service", Node.from("smithy.example#Example")) + .withMember("package", Node.from("example")) + .withMember("packageVersion", Node.from("1.0.0")) + .build()) + .build(); new TypeScriptCodegenPlugin().execute(context); String contents = manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "//commands/GetFooCommand.ts").get(); assertThat(contents, containsString("as __MetadataBearer")); - assertThat(contents, containsString(expectedType)); + for (String expectedType : expectedTypeArray) { + assertThat(contents, containsString(expectedType)); + } } } diff --git a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy new file mode 100644 index 00000000000..95494d61853 --- /dev/null +++ b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy @@ -0,0 +1,44 @@ +$version: "2.0" + +namespace smithy.example + +@smithy.rules#endpointRuleSet({ + version: "1.0", + parameters: { + opContextParamIdentifier: { + type: "string", + }, + opContextParamSubExpression: { + type: "string", + }, + }, + rules: [] +}) +service Example { + version: "1.0.0", + operations: [GetFoo] +} + +@smithy.rules#operationContextParams( + "opContextParamIdentifier": { path: "fooString" } + "opContextParamSubExpression": { path: "fooObj.bar" } +) +operation GetFoo { + input: GetFooInput, + output: GetFooOutput, + errors: [GetFooError] +} + +structure GetFooInput { + fooString: String, + fooObj: FooObject +} + +structure FooObject { + bar: String +} + +structure GetFooOutput {} + +@error("client") +structure GetFooError {} From 1e7e865af19e895dcda1d93faca0972a3c43da59 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:38:53 +0000 Subject: [PATCH 07/13] Use map for hash wildcard expressions --- .../codegen/endpointsV2/RuleSetParameterFinder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 a821ba2f013..94fdb8aa429 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 @@ -187,7 +187,7 @@ public Map getOperationContextParamValues(OperationShape operati if (part.endsWith("[*]")) { // Get key to run hash wildcard on. String key = part.substring(0, part.length() - 3); - value = "Object.values(" + value + separator + key + ")"; + value = value + separator + key + separator + "map(obj => obj"; continue; } @@ -195,6 +195,9 @@ public Map getOperationContextParamValues(OperationShape operati value += separator + part; } + // Close all open brackets. + value += ")".repeat((int) value.chars().filter(ch -> ch == '(').count()); + map.put(name, value); }); } From b969772fa2697d4866b75478a20baccc29e253b5 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:39:22 +0000 Subject: [PATCH 08/13] Add tests for Operation Context Params List Wildcard Expressions --- .../codegen/CommandGeneratorTest.java | 2 ++ .../endpoints-operation-context-params.smithy | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java index e7dc383f3d7..e4c9c2d631f 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java @@ -41,6 +41,8 @@ public void writesOperationContextParamValues() { new String[] { "opContextParamIdentifier: { type: \"operationContextParams\", name: this.input.fooString }", "opContextParamSubExpression: { type: \"operationContextParams\", name: this.input.fooObj.bar }", + "opContextParamWildcardExpressionList: { type: \"operationContextParams\", name: this.input.fooList.map(obj => obj) }", + "opContextParamWildcardExpressionListObj: { type: \"operationContextParams\", name: this.input.fooListObj.map(obj => obj.key) }", } ); } diff --git a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy index 95494d61853..a193ab19927 100644 --- a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy +++ b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy @@ -11,6 +11,12 @@ namespace smithy.example opContextParamSubExpression: { type: "string", }, + opContextParamWildcardExpressionList: { + type: "stringArray", + }, + opContextParamWildcardExpressionListObj: { + type: "stringArray", + }, }, rules: [] }) @@ -22,6 +28,8 @@ service Example { @smithy.rules#operationContextParams( "opContextParamIdentifier": { path: "fooString" } "opContextParamSubExpression": { path: "fooObj.bar" } + "opContextParamWildcardExpressionList": { path: "fooList[*]" } + "opContextParamWildcardExpressionListObj": { path: "fooListObj[*].key" } ) operation GetFoo { input: GetFooInput, @@ -31,13 +39,27 @@ operation GetFoo { structure GetFooInput { fooString: String, - fooObj: FooObject + fooObj: FooObject, + fooList: FooList, + fooListObj: FooListObj, } structure FooObject { bar: String } +list FooList { + member: String +} + +list FooListObj { + member: FooListObjMember +} + +structure FooListObjMember { + key: String +} + structure GetFooOutput {} @error("client") From 25dfe68125f303956bc5b16743044d067257432b Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:43:03 +0000 Subject: [PATCH 09/13] Add a mapper if Object values need to be processed --- .../codegen/endpointsV2/RuleSetParameterFinder.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 94fdb8aa429..b0ad8de8ca0 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 @@ -169,6 +169,11 @@ public Map getOperationContextParamValues(OperationShape operati // Split JMESPath expression string on separator and add JavaScript equivalent. for (String part : path.split("[" + separator + "]")) { + if (value.endsWith(")")) { + // The value is an object, which needs to run on map. + value += ".map(obj => obj"; + } + // Process keys https://jmespath.org/specification.html#keys if (part.startsWith("keys(")) { // Get provided object for which keys are to be extracted. @@ -196,7 +201,8 @@ public Map getOperationContextParamValues(OperationShape operati } // Close all open brackets. - value += ")".repeat((int) value.chars().filter(ch -> ch == '(').count()); + value += ")".repeat((int) ( + value.chars().filter(ch -> ch == '(').count() - value.chars().filter(ch -> ch == ')').count())); map.put(name, value); }); From 1782bdbb03d995fd871a478bb9017c496cd34c9c Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:51:09 +0000 Subject: [PATCH 10/13] Add tests for Operation Context Params Hash Wildcard Expressions --- .../smithy/typescript/codegen/CommandGeneratorTest.java | 1 + .../endpoints-operation-context-params.smithy | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java index e4c9c2d631f..c3244e29848 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java @@ -43,6 +43,7 @@ public void writesOperationContextParamValues() { "opContextParamSubExpression: { type: \"operationContextParams\", name: this.input.fooObj.bar }", "opContextParamWildcardExpressionList: { type: \"operationContextParams\", name: this.input.fooList.map(obj => obj) }", "opContextParamWildcardExpressionListObj: { type: \"operationContextParams\", name: this.input.fooListObj.map(obj => obj.key) }", + "opContextParamWildcardExpressionHash: { type: \"operationContextParams\", name: Object.values(this.input.fooObjObj).map(obj => obj.bar) }", } ); } diff --git a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy index a193ab19927..f45be63c6c1 100644 --- a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy +++ b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy @@ -17,6 +17,9 @@ namespace smithy.example opContextParamWildcardExpressionListObj: { type: "stringArray", }, + opContextParamWildcardExpressionHash: { + type: "stringArray", + }, }, rules: [] }) @@ -30,6 +33,7 @@ service Example { "opContextParamSubExpression": { path: "fooObj.bar" } "opContextParamWildcardExpressionList": { path: "fooList[*]" } "opContextParamWildcardExpressionListObj": { path: "fooListObj[*].key" } + "opContextParamWildcardExpressionHash": { path: "fooObjObj.*.bar" } ) operation GetFoo { input: GetFooInput, @@ -40,6 +44,7 @@ operation GetFoo { structure GetFooInput { fooString: String, fooObj: FooObject, + fooObjObj: FooObjectObject, fooList: FooList, fooListObj: FooListObj, } @@ -48,6 +53,10 @@ structure FooObject { bar: String } +structure FooObjectObject { + baz: FooObject +} + list FooList { member: String } From 459774a9b846ac1901f4aa04ee26ff42d88760b5 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:43:28 +0000 Subject: [PATCH 11/13] Add tests for JMESPath keys --- .../typescript/codegen/CommandGeneratorTest.java | 1 + .../endpoints-operation-context-params.smithy | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java index c3244e29848..b4f443ad538 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java @@ -44,6 +44,7 @@ public void writesOperationContextParamValues() { "opContextParamWildcardExpressionList: { type: \"operationContextParams\", name: this.input.fooList.map(obj => obj) }", "opContextParamWildcardExpressionListObj: { type: \"operationContextParams\", name: this.input.fooListObj.map(obj => obj.key) }", "opContextParamWildcardExpressionHash: { type: \"operationContextParams\", name: Object.values(this.input.fooObjObj).map(obj => obj.bar) }", + "opContextParamKeys: { type: \"operationContextParams\", name: Object.keys(this.input.fooKeys) }", } ); } diff --git a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy index f45be63c6c1..f947e482e34 100644 --- a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy +++ b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints-operation-context-params.smithy @@ -20,6 +20,9 @@ namespace smithy.example opContextParamWildcardExpressionHash: { type: "stringArray", }, + opContextParamKeys: { + type: "stringArray", + }, }, rules: [] }) @@ -34,6 +37,7 @@ service Example { "opContextParamWildcardExpressionList": { path: "fooList[*]" } "opContextParamWildcardExpressionListObj": { path: "fooListObj[*].key" } "opContextParamWildcardExpressionHash": { path: "fooObjObj.*.bar" } + "opContextParamKeys": { path: "keys(fooKeys)" } ) operation GetFoo { input: GetFooInput, @@ -42,11 +46,12 @@ operation GetFoo { } structure GetFooInput { - fooString: String, - fooObj: FooObject, - fooObjObj: FooObjectObject, + fooKeys: FooObject, fooList: FooList, fooListObj: FooListObj, + fooObj: FooObject, + fooObjObj: FooObjectObject, + fooString: String, } structure FooObject { From a7c13a7ebcf4a50aff4c8b3fbd9819d0883e1715 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:44:00 +0000 Subject: [PATCH 12/13] Remove redundant variable operationContextParamsTrait --- .../typescript/codegen/endpointsV2/RuleSetParameterFinder.java | 3 +-- 1 file changed, 1 insertion(+), 2 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 b0ad8de8ca0..896ce3ff3ed 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 @@ -161,8 +161,7 @@ public Map getOperationContextParamValues(OperationShape operati Optional trait = operation.getTrait(OperationContextParamsTrait.class); if (trait.isPresent()) { - OperationContextParamsTrait operationContextParamsTrait = trait.get(); - operationContextParamsTrait.getParameters().forEach((name, definition) -> { + trait.get().getParameters().forEach((name, definition) -> { String separator = "."; String value = "this" + separator + "input"; String path = definition.getPath(); From 9d7af2190d9ca3d16dfcf5b2ea7d834e1f39dfb7 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:54:18 +0000 Subject: [PATCH 13/13] Remove no-op map from OperationContextParamValues --- .../codegen/endpointsV2/RuleSetParameterFinder.java | 5 +++++ .../smithy/typescript/codegen/CommandGeneratorTest.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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 896ce3ff3ed..44831958b97 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 @@ -199,6 +199,11 @@ public Map getOperationContextParamValues(OperationShape operati value += separator + part; } + // Remove no-op map, if it exists. + if (value.endsWith(separator + "map(obj => obj")) { + value = value.substring(0, value.length() - 15); + } + // Close all open brackets. value += ")".repeat((int) ( value.chars().filter(ch -> ch == '(').count() - value.chars().filter(ch -> ch == ')').count())); diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java index b4f443ad538..9289684b4a1 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java @@ -41,7 +41,7 @@ public void writesOperationContextParamValues() { new String[] { "opContextParamIdentifier: { type: \"operationContextParams\", name: this.input.fooString }", "opContextParamSubExpression: { type: \"operationContextParams\", name: this.input.fooObj.bar }", - "opContextParamWildcardExpressionList: { type: \"operationContextParams\", name: this.input.fooList.map(obj => obj) }", + "opContextParamWildcardExpressionList: { type: \"operationContextParams\", name: this.input.fooList }", "opContextParamWildcardExpressionListObj: { type: \"operationContextParams\", name: this.input.fooListObj.map(obj => obj.key) }", "opContextParamWildcardExpressionHash: { type: \"operationContextParams\", name: Object.values(this.input.fooObjObj).map(obj => obj.bar) }", "opContextParamKeys: { type: \"operationContextParams\", name: Object.keys(this.input.fooKeys) }",