From 047cbe923034ebb2ea5d6c408a45aaf681c63032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Madrigal=20=F0=9F=90=A7?= <599908+Madrigal@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:13:25 -0400 Subject: [PATCH] Allow all headers to be set to an empty value --- .../integration/HttpBindingProtocolGenerator.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java index f3ced75e..922f5cb8 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java @@ -852,10 +852,8 @@ private void writeHttpBindingMember( }); } - boolean allowZeroStrings = location != HttpBinding.Location.HEADER; - GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer, - memberShape, "v", allowZeroStrings, memberShape.isRequired(), (operand) -> { + memberShape, "v", true, memberShape.isRequired(), (operand) -> { final String locationName = binding.getLocationName().isEmpty() ? memberShape.getMemberName() : binding.getLocationName(); switch (location) { @@ -980,6 +978,13 @@ private void writeHeaderBinding( } MemberShape collectionMemberShape = CodegenUtils.expectCollectionShape(targetShape).getMember(); + // On empty collection header will be set to an empty value + writer.openBlock("if len($L) == 0 {", "}", operand, () -> { + writeHttpBindingSetter(context, writer, collectionMemberShape, location, operand, + (w, s) -> { + w.writeInline("$L.AddHeader($L).String(\"\")", dest, locationName); + }); + }); writer.openBlock("for i := range $L {", "}", operand, () -> { // Only set non-empty non-nil header values String indexedOperand = operand + "[i]";