From fb5e27ea9dca00ab4ef97c2b83a43fd42f523d02 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 24 Apr 2020 12:55:50 -0700 Subject: [PATCH 1/2] 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. --- .../integration/HttpBindingProtocolGenerator.java | 12 +++++++----- .../integration/HttpRpcProtocolGenerator.java | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java index 8bb617172e2..818fff6d9f3 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java @@ -227,16 +227,19 @@ private void generateOperationSerializer( HttpProtocolGeneratorUtils.writeHostPrefix(context, operation); } + writer.write("const {hostname, protocol = \"https\", port} = await context.endpoint();"); 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. @@ -246,8 +249,7 @@ private void generateOperationSerializer( .forEach(serializingDocumentShapes::add); } // Always set the body, - writer.write("body: body,"); - writer.write("...context.endpoint,"); + writer.write("body,"); }); }); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java index 8ff75bc339a..6ef80762abd 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java @@ -100,19 +100,21 @@ 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, () -> { + 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;"); From cfc891037ef7e4ae0ee31314c2b13a62d4c2895a Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Fri, 24 Apr 2020 16:03:31 -0700 Subject: [PATCH 2/2] add inline documents --- .../codegen/integration/HttpBindingProtocolGenerator.java | 2 ++ .../codegen/integration/HttpRpcProtocolGenerator.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java index 818fff6d9f3..7858de905a3 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java @@ -227,6 +227,8 @@ 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();"); writer.openBlock("return new $T({", "});", requestType, () -> { if (hasHostPrefix) { diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java index 6ef80762abd..d12354f2c7e 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java @@ -107,6 +107,8 @@ public void generateSharedComponents(GenerationContext context) { + " resolvedHostname: string | undefined,\n" + " body: any,\n" + "): 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,");