Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thick-socks-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/middleware-endpoint": patch
---

fix for operation context params
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ subprojects {
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
} else {
tasks.test {
testLogging {
events("failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export const resolveParams = async <
case "builtInParams":
endpointParams[name] = await createConfigValueProvider<Config>(instruction.name, name, clientConfig)();
break;
case "operationContextParams":
endpointParams[name] = instruction.get(commandInput);
break;
default:
throw new Error("Unrecognized endpoint parameter instruction: " + JSON.stringify(instruction));
}
Expand Down
11 changes: 10 additions & 1 deletion packages/middleware-endpoint/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface EndpointParameterInstructions {
| BuiltInParamInstruction
| ClientContextParamInstruction
| StaticContextParamInstruction
| ContextParamInstruction;
| ContextParamInstruction
| OperationContextParamInstruction;
}

/**
Expand Down Expand Up @@ -40,3 +41,11 @@ export interface ContextParamInstruction {
type: "contextParams";
name: string; // The input structure's member name that has contextParams trait
}

/**
* @internal
*/
export interface OperationContextParamInstruction {
type: "operationContextParams";
get(input: any): any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I assume that the path expression is solely based on the input? No other parameters are needed, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As per internal documentation

The operationContextParams trait defines one or more context parameters that MUST be bound to values specified in the operation input using a JMESPath expression

}
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\", name: $L },
$L: { type: \"operationContextParams\", get: (input: any) => $L },
""",
name, jmesPathForInputInJs);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ public Map<String, String> getOperationContextParamValues(OperationShape operati
if (trait.isPresent()) {
trait.get().getParameters().forEach((name, definition) -> {
String separator = ".";
String value = "this" + separator + "input";
String value = "input";
String path = definition.getPath();

// 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";
value += ".map((obj: any) => obj";
}

// Process keys https://jmespath.org/specification.html#keys
Expand All @@ -303,7 +303,7 @@ public Map<String, String> getOperationContextParamValues(OperationShape operati
if (part.endsWith("[*]")) {
// Get key to run hash wildcard on.
String key = part.substring(0, part.length() - 3);
value = value + separator + key + separator + "map(obj => obj";
value = value + separator + key + separator + "map((obj: any) => obj";
continue;
}

Expand All @@ -312,8 +312,9 @@ public Map<String, String> getOperationContextParamValues(OperationShape operati
}

// Remove no-op map, if it exists.
if (value.endsWith(separator + "map(obj => obj")) {
value = value.substring(0, value.length() - 15);
final String noOpMap = "map((obj: any) => obj";
if (value.endsWith(separator + noOpMap)) {
value = value.substring(0, value.length() - noOpMap.length() - separator.length());
}

// Close all open brackets.
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\", name: this.input.fooString }",
"opContextParamSubExpression: { type: \"operationContextParams\", name: this.input.fooObj.bar }",
"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) }",
"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
Loading