Skip to content

Commit fb5e27e

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 fb5e27e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,19 @@ private void generateOperationSerializer(
227227
HttpProtocolGeneratorUtils.writeHostPrefix(context, operation);
228228
}
229229

230+
writer.write("const {hostname, protocol = \"https\", 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,");
236+
writer.write("hostname,");
237+
writer.write("port,");
235238
writer.write("method: $S,", trait.getMethod());
236-
writer.write("headers: headers,");
239+
writer.write("headers,");
237240
writer.write("path: resolvedPath,");
238241
if (hasQueryComponents) {
239-
writer.write("query: query,");
242+
writer.write("query,");
240243
}
241244
if (!bodyBindings.isEmpty()) {
242245
// Track all shapes bound to the body so their serializers may be generated.
@@ -246,8 +249,7 @@ private void generateOperationSerializer(
246249
.forEach(serializingDocumentShapes::add);
247250
}
248251
// Always set the body,
249-
writer.write("body: body,");
250-
writer.write("...context.endpoint,");
252+
writer.write("body,");
251253
});
252254
});
253255

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

Lines changed: 8 additions & 6 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 = \"https\", port} = await context.endpoint();");
110111
writer.openBlock("const contents: any = {", "};", () -> {
111-
writer.write("protocol: \"https\",");
112+
writer.write("protocol,");
113+
writer.write("hostname,");
114+
writer.write("port,");
112115
writer.write("method: \"POST\",");
113-
writer.write("path: path,");
114-
writer.write("headers: headers,");
115-
writer.write("...context.endpoint,");
116+
writer.write("path,");
117+
writer.write("headers,");
116118
});
117119
writer.openBlock("if (resolvedHostname !== undefined) {", "}", () -> {
118120
writer.write("contents.hostname = resolvedHostname;");

0 commit comments

Comments
 (0)