diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java index 8c9fc1096eb..063cdc63756 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java @@ -235,6 +235,9 @@ private void generateClientRequestTest(OperationShape operation, HttpRequestTest // Create a client with a custom request handler that intercepts requests. writer.openBlock("const client = new $T({", "});\n", serviceSymbol, () -> { writer.write("...clientParams,"); + testCase.getHost().ifPresent(host -> { + writer.write("endpoint: \"https://$L\",", host); + }); writer.write("requestHandler: new RequestSerializationTestHandler(),"); }); 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 7fdc1884640..576f2708af6 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 @@ -599,6 +599,11 @@ private void generateOperationRequestSerializer( + " input: $T,\n" + " context: $L\n" + "): Promise<$T> => {", "}", methodName, inputType, contextType, requestType, () -> { + + // Get the hostname, path, 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 = $S, port, path: basePath} = await context.endpoint();", "https"); + writeRequestHeaders(context, operation, bindingIndex); writeResolvedPath(context, operation, bindingIndex, trait); boolean hasQueryComponents = writeRequestQueryString(context, operation, bindingIndex, trait); @@ -616,10 +621,6 @@ private void generateOperationRequestSerializer( if (hasHostPrefix) { 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, () -> { writer.write("protocol,"); if (hasHostPrefix) { @@ -683,7 +684,9 @@ private void writeResolvedPath( List labelBindings = bindingIndex.getRequestBindings(operation, Location.LABEL); // Always write the bound path, but only the actual segments. - writer.write("let resolvedPath = $S;", "/" + trait.getUri().getSegments().stream() + writer.write("let resolvedPath = `$L` + $S;", + "${basePath?.endsWith('/') ? basePath.slice(0, -1) : (basePath || '')}", + "/" + trait.getUri().getSegments().stream() .map(Segment::toString) .collect(Collectors.joining("/")));