Skip to content

fix: resolve endpoint in command serializer #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,21 @@ private void generateOperationSerializer(
HttpProtocolGeneratorUtils.writeHostPrefix(context, operation);
}

// Get the hostname, port, and scheme from client's resolved endpoint. Then construct the request from
// them. The client's resolved endpoint can be default one or supplied by users.
writer.write("const {hostname, protocol = \"https\", port} = await context.endpoint();");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comments describing what this setup is doing and why it's necessary, in each of the files?

writer.openBlock("return new $T({", "});", requestType, () -> {
if (hasHostPrefix) {
writer.write("hostname: resolvedHostname,");
}
writer.write("protocol: \"https\",");
writer.write("protocol,");
writer.write("hostname,");
writer.write("port,");
writer.write("method: $S,", trait.getMethod());
writer.write("headers: headers,");
writer.write("headers,");
writer.write("path: resolvedPath,");
if (hasQueryComponents) {
writer.write("query: query,");
writer.write("query,");
}
if (!bodyBindings.isEmpty()) {
// Track all shapes bound to the body so their serializers may be generated.
Expand All @@ -246,8 +251,7 @@ private void generateOperationSerializer(
.forEach(serializingDocumentShapes::add);
}
// Always set the body,
writer.write("body: body,");
writer.write("...context.endpoint,");
writer.write("body,");
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,23 @@ public void generateSharedComponents(GenerationContext context) {
writer.addUseImports(requestType);
writer.addImport("SerdeContext", "__SerdeContext", "@aws-sdk/types");
writer.addImport("HeaderBag", "__HeaderBag", "@aws-sdk/types");
writer.openBlock("const buildHttpRpcRequest = (\n"
writer.openBlock("const buildHttpRpcRequest = async (\n"
+ " context: __SerdeContext,\n"
+ " headers: __HeaderBag,\n"
+ " path: string,\n"
+ " resolvedHostname: string | undefined,\n"
+ " body: any,\n"
+ "): $T => {", "};", requestType, () -> {
+ "): Promise<$T> => {", "};", requestType, () -> {
// Get the hostname, port, and scheme from client's resolved endpoint. Then construct the request from
// them. The client's resolved endpoint can be default one or supplied by users.
writer.write("const {hostname, protocol = \"https\", port} = await context.endpoint();");
writer.openBlock("const contents: any = {", "};", () -> {
writer.write("protocol: \"https\",");
writer.write("protocol,");
writer.write("hostname,");
writer.write("port,");
writer.write("method: \"POST\",");
writer.write("path: path,");
writer.write("headers: headers,");
writer.write("...context.endpoint,");
writer.write("path,");
writer.write("headers,");
});
writer.openBlock("if (resolvedHostname !== undefined) {", "}", () -> {
writer.write("contents.hostname = resolvedHostname;");
Expand Down