Skip to content

Commit 9203a7e

Browse files
author
Chase Coalwell
authored
Collect unused stream bodies (#133)
1 parent 460cef2 commit 9203a7e

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ private List<HttpBinding> readResponseBody(
787787
if (!payloadBindings.isEmpty()) {
788788
return readResponsePayload(context, operationOrError, payloadBindings);
789789
}
790+
791+
// If there are no payload or document bindings, the body still needs collected so the process can exit.
792+
writer.write("await collectBody(output.body, context);");
790793
return ListUtils.of();
791794
}
792795

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import software.amazon.smithy.model.traits.ErrorTrait;
2929
import software.amazon.smithy.typescript.codegen.ApplicationProtocol;
3030
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
31+
import software.amazon.smithy.utils.OptionalUtils;
3132

3233
/**
3334
* Abstract implementation useful for all HTTP protocols without bindings.
@@ -382,20 +383,26 @@ private void generateErrorDeserializer(GenerationContext context, StructureShape
382383
}
383384

384385
private void readResponseBody(GenerationContext context, OperationShape operation) {
385-
operation.getOutput().ifPresent(outputId -> {
386-
// We only need to load the body and prepare a contents object if there is a response.
387-
TypeScriptWriter writer = context.getWriter();
388-
writer.write("const data: any = await parseBody(output.body, context)");
389-
writer.write("let contents: any = {};");
390-
391-
// If there's an output present, we know it's a structure.
392-
StructureShape outputShape = context.getModel().expectShape(outputId).asStructureShape().get();
393-
394-
// Track output shapes so their deserializers may be generated.
395-
deserializingDocumentShapes.add(outputShape);
396-
397-
deserializeOutputDocument(context, operation, outputShape);
398-
});
386+
TypeScriptWriter writer = context.getWriter();
387+
OptionalUtils.ifPresentOrElse(
388+
operation.getOutput(),
389+
outputId -> {
390+
// We only need to load the body and prepare a contents object if there is a response.
391+
writer.write("const data: any = await parseBody(output.body, context)");
392+
writer.write("let contents: any = {};");
393+
394+
// If there's an output present, we know it's a structure.
395+
StructureShape outputShape = context.getModel().expectShape(outputId).asStructureShape().get();
396+
397+
// Track output shapes so their deserializers may be generated.
398+
deserializingDocumentShapes.add(outputShape);
399+
400+
deserializeOutputDocument(context, operation, outputShape);
401+
},
402+
() -> {
403+
// If there is no output, the body still needs to be collected so the process can exit.
404+
writer.write("await collectBody(output.body, context);");
405+
});
399406
}
400407

401408
/**

0 commit comments

Comments
 (0)