diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index 8a1ec493b4f..882ff749ab8 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -104,6 +104,7 @@ public void run() { writer.writeShapeDocs(operation); writer.openBlock("export class $L extends $$Command<$T, $T, $L> {", "}", name, inputType, outputType, configType, () -> { + writer.write("private resolved = false;"); // Section for adding custom command properties. writer.write("// Start section: $L", COMMAND_PROPERTIES_SECTION); @@ -145,11 +146,15 @@ private void generateCommandMiddlewareResolver(String configType) { .write("options?: $T", applicationProtocol.getOptionsType()) .dedent(); writer.openBlock("): Handler<$T, $T> {", "}", inputType, outputType, () -> { - // Add serialization and deserialization plugin. - writer.write("this.middlewareStack.use($T(configuration, this.serialize, this.deserialize));", serde); + writer.openBlock("if (!this.resolved) {", "}", () -> { + // Add serialization and deserialization plugin. + writer.write("this.middlewareStack.use($T(configuration, this.serialize, this.deserialize));", serde); - // Add customizations. - addCommandSpecificPlugins(); + // Add customizations. + addCommandSpecificPlugins(); + + writer.write("this.resolved = true;"); + }); // Resolve the middleware stack. writer.write("\nconst stack = clientStack.concat(this.middlewareStack);\n"); diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java index a2468ba1a04..ca22a49e6c3 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/CommandGeneratorTest.java @@ -18,7 +18,10 @@ public void addsCommandSpecificPlugins() { " configuration: ExampleClientResolvedConfig,\n" + " options?: __HttpHandlerOptions\n" + " ): Handler {\n" + - " this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));\n" + + " if (!this.resolved) {\n" + + " this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));\n" + + " this.resolved = true;\n" + + " }\n" + "\n" + " const stack = clientStack.concat(this.middlewareStack);"); }