Skip to content

Commit 02f9506

Browse files
committed
fix: resolve endpoint in command serializer
The endpoint used to be a function returning a promise of Endpoint, and it is resolved in serializer parameter. It introduces mismatch between SerDeContext type and the value, where the value contains resolved endpoint but the type is a provider function returning Endpoint promise. This change assumes the SerDeContext.endpoint is actually a provider function and only resolve the promise when constructing a request. This change also fix the issue that the request resolved path got overwritten by '/'. Now only the hostname, port and scheme from client endpoint config is persisted when creating a request.
1 parent 89b7e6f commit 02f9506

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,14 @@ private void generateOperationSerializer(
227227
HttpProtocolGeneratorUtils.writeHostPrefix(context, operation);
228228
}
229229

230+
writer.write("const {hostname, protocol, port} = await context.endpoint();");
230231
writer.openBlock("return new $T({", "});", requestType, () -> {
231232
if (hasHostPrefix) {
232233
writer.write("hostname: resolvedHostname,");
233234
}
234-
writer.write("protocol: \"https\",");
235+
writer.write("protocol: \"https\" || protocol,");
236+
writer.write("hostname,");
237+
writer.write("port,");
235238
writer.write("method: $S,", trait.getMethod());
236239
writer.write("headers: headers,");
237240
writer.write("path: resolvedPath,");
@@ -247,7 +250,6 @@ private void generateOperationSerializer(
247250
}
248251
// Always set the body,
249252
writer.write("body: body,");
250-
writer.write("...context.endpoint,");
251253
});
252254
});
253255

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,21 @@ public void generateSharedComponents(GenerationContext context) {
100100
writer.addUseImports(requestType);
101101
writer.addImport("SerdeContext", "__SerdeContext", "@aws-sdk/types");
102102
writer.addImport("HeaderBag", "__HeaderBag", "@aws-sdk/types");
103-
writer.openBlock("const buildHttpRpcRequest = (\n"
103+
writer.openBlock("const buildHttpRpcRequest = async (\n"
104104
+ " context: __SerdeContext,\n"
105105
+ " headers: __HeaderBag,\n"
106106
+ " path: string,\n"
107107
+ " resolvedHostname: string | undefined,\n"
108108
+ " body: any,\n"
109-
+ "): $T => {", "};", requestType, () -> {
109+
+ "): Promise<$T> => {", "};", requestType, () -> {
110+
writer.write("const {hostname, protocol, port} = await context.endpoint();");
110111
writer.openBlock("const contents: any = {", "};", () -> {
111-
writer.write("protocol: \"https\",");
112+
writer.write("protocol: \"https\" || protocol,");
113+
writer.write("hostname,");
114+
writer.write("port,");
112115
writer.write("method: \"POST\",");
113116
writer.write("path: path,");
114117
writer.write("headers: headers,");
115-
writer.write("...context.endpoint,");
116118
});
117119
writer.openBlock("if (resolvedHostname !== undefined) {", "}", () -> {
118120
writer.write("contents.hostname = resolvedHostname;");

0 commit comments

Comments
 (0)