|
28 | 28 | import software.amazon.smithy.model.traits.ErrorTrait;
|
29 | 29 | import software.amazon.smithy.typescript.codegen.ApplicationProtocol;
|
30 | 30 | import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
|
| 31 | +import software.amazon.smithy.utils.OptionalUtils; |
31 | 32 |
|
32 | 33 | /**
|
33 | 34 | * Abstract implementation useful for all HTTP protocols without bindings.
|
@@ -382,20 +383,26 @@ private void generateErrorDeserializer(GenerationContext context, StructureShape
|
382 | 383 | }
|
383 | 384 |
|
384 | 385 | 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 | + }); |
399 | 406 | }
|
400 | 407 |
|
401 | 408 | /**
|
|
0 commit comments