From dddbe3c972dcc794a0fd5fe98d4238f61777a4a9 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Mon, 17 Jun 2024 09:10:57 -0700 Subject: [PATCH] Fix logic for deciding whether to write a default input body (#1304) --- .../codegen/integration/HttpBindingProtocolGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java index c21e4e437e3..8b4a5503db5 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java @@ -1096,7 +1096,7 @@ private void writeContentTypeHeader(GenerationContext context, Shape operationOr optionalContentType = bindingIndex.determineResponseContentType(operationOrError, getDocumentContentType()); } // If we need to write a default body then it needs a content type. - if (!optionalContentType.isPresent() && shouldWriteDefaultBody(context, operationOrError, isInput)) { + if (optionalContentType.isEmpty() && shouldWriteDefaultBody(context, operationOrError, isInput)) { optionalContentType = Optional.of(getDocumentContentType()); } optionalContentType.ifPresent(contentType -> { @@ -1143,8 +1143,8 @@ private boolean shouldWriteDefaultBody(GenerationContext context, Shape operatio } /** - * Given a context and operation, should a default input body be written. By default no body will be written - * if there are no members bound to the input. + * Given a context and operation, should a default input body be written. By default, a body + * will be written if and only if there are payload members bound to the input. * * @param context The generation context. * @param operation The operation whose input is being serialized. @@ -1152,7 +1152,7 @@ private boolean shouldWriteDefaultBody(GenerationContext context, Shape operatio * @return True if a default body should be generated. */ protected boolean shouldWriteDefaultInputBody(GenerationContext context, OperationShape operation) { - return HttpBindingIndex.of(context.getModel()).getRequestBindings(operation).isEmpty(); + return HttpBindingIndex.of(context.getModel()).hasRequestBody(operation); } /**