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 72cc892ba28..d72698e1969 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 @@ -210,6 +210,37 @@ private void generateClientCommand() { .protocolGenerator(protocolGenerator) .applicationProtocol(applicationProtocol) .build()); + + { + // This block places the most commonly sought type definitions + // closer to the command definition, for navigation assistance + // in IDEs. + Shape operationInputShape = model.expectShape(operation.getInputShape()); + Symbol baseInput = symbolProvider.toSymbol(operationInputShape); + Shape operationOutputShape = model.expectShape(operation.getOutputShape()); + Symbol baseOutput = symbolProvider.toSymbol(operationOutputShape); + + writer.write("/** @internal type navigation helper, not in runtime. */"); + writer.openBlock("declare protected static __types: {", "};", () -> { + String baseInputStr = operationInputShape.getAllMembers().isEmpty() + ? "{}" + : baseInput.getName(); + String baseOutputStr = operationOutputShape.getAllMembers().isEmpty() + ? "{}" + : baseOutput.getName(); + writer.write(""" + api: { + input: $L; + output: $L; + };""", baseInputStr, baseOutputStr); + writer.write(""" + sdk: { + input: $T; + output: $T; + };""", inputType, outputType); + }); + } + writer.write("}"); // class close bracket. }