Skip to content

Commit

Permalink
no-throw on invoking operationContextParams getter
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Dec 19, 2024
1 parent f7ada55 commit 3b3ba74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void generateEndpointParameterInstructionProvider() {
operationContextParamValues.forEach((name, jmesPathForInputInJs) -> {
writer.write(
"""
$L: { type: \"operationContextParams\", get: (input: any) => $L },
$L: { type: \"operationContextParams\", get: (input?: any) => $L },
""",
name, jmesPathForInputInJs);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public Map<String, String> getOperationContextParamValues(OperationShape operati
Optional<OperationContextParamsTrait> trait = operation.getTrait(OperationContextParamsTrait.class);
if (trait.isPresent()) {
trait.get().getParameters().forEach((name, definition) -> {
String separator = ".";
String separator = "?.";
String value = "input";
String path = definition.getPath();

Expand All @@ -289,13 +289,13 @@ public Map<String, String> getOperationContextParamValues(OperationShape operati
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 + ")";
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 + ")";
value = "Object.values(" + value + " ?? {})";
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public void writesOperationContextParamValues() {
testCommmandCodegen(
"endpointsV2/endpoints-operation-context-params.smithy",
new String[] {
"opContextParamIdentifier: { type: \"operationContextParams\", get: (input: any) => input.fooString }",
"opContextParamSubExpression: { type: \"operationContextParams\", get: (input: any) => input.fooObj.bar }",
"opContextParamWildcardExpressionList: { type: \"operationContextParams\", get: (input: any) => input.fooList }",
"opContextParamWildcardExpressionListObj: { type: \"operationContextParams\", get: (input: any) => input.fooListObj.map((obj: any) => obj.key) }",
"opContextParamWildcardExpressionHash: { type: \"operationContextParams\", get: (input: any) => Object.values(input.fooObjObj).map((obj: any) => obj.bar) }",
"opContextParamKeys: { type: \"operationContextParams\", get: (input: any) => Object.keys(input.fooKeys) }",
"opContextParamIdentifier: { type: \"operationContextParams\", get: (input?: any) => input?.fooString }",
"opContextParamSubExpression: { type: \"operationContextParams\", get: (input?: any) => input?.fooObj?.bar }",
"opContextParamWildcardExpressionList: { type: \"operationContextParams\", get: (input?: any) => input?.fooList }",
"opContextParamWildcardExpressionListObj: { type: \"operationContextParams\", get: (input?: any) => input?.fooListObj?.map((obj: any) => obj?.key) }",
"opContextParamWildcardExpressionHash: { type: \"operationContextParams\", get: (input?: any) => Object.values(input?.fooObjObj ?? {}).map((obj: any) => obj?.bar) }",
"opContextParamKeys: { type: \"operationContextParams\", get: (input?: any) => Object.keys(input?.fooKeys ?? {}) }",
}
);
}
Expand Down

0 comments on commit 3b3ba74

Please sign in to comment.