Skip to content
Draft
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 @@ -49,6 +49,7 @@
import software.amazon.smithy.model.traits.DocumentationTrait;
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.model.traits.InternalTrait;
import software.amazon.smithy.model.traits.StreamingTrait;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.typescript.codegen.documentation.StructureExampleGenerator;
import software.amazon.smithy.typescript.codegen.endpointsV2.RuleSetParameterFinder;
Expand Down Expand Up @@ -260,6 +261,7 @@ private String getCommandExample(String serviceName, String configName, String c
model.getShape(operation.getInputShape()).get(), model, false, true))
+ String.format("const command = new %s(input);%n", commandName)
+ "const response = await client.send(command);\n"
+ getReadStreamExample()
+ String.format("%s%n",
StructureExampleGenerator.generateStructuralHintDocumentation(
model.getShape(operation.getOutputShape()).get(), model, true, false))
Expand All @@ -272,6 +274,30 @@ private String getCommandExample(String serviceName, String configName, String c
+ String.format("@see {@link %s | config} for %s's `config` shape.%n", configName, serviceName);
}

private String getReadStreamExample() {
String streamingBlobOutputMemberName = model.expectShape(operation.getOutputShape())
.asStructureShape().get()
.getAllMembers()
.values()
.stream()
.filter(ms -> {
Shape target = model.expectShape(ms.getTarget());
return target.isBlobShape()
&& (ms.hasTrait(StreamingTrait.class) || target.hasTrait(StreamingTrait.class));
})
.findFirst()
.map(MemberShape::getMemberName)
.orElse("");

if (!streamingBlobOutputMemberName.isEmpty()) {
return """
// Read the stream or discard it to free the socket.
const bytes = await response[`%s`].transformToByteArray();\n"""
.formatted(streamingBlobOutputMemberName);
}
return "";
}

private String getThrownExceptions() {
List<ShapeId> errors = operation.getErrors();
StringBuilder buffer = new StringBuilder();
Expand Down