Skip to content

Commit

Permalink
do NOT serialize empty lists in ec2query
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed May 6, 2024
1 parent ee219f2 commit 20c1ea1
Show file tree
Hide file tree
Showing 3 changed files with 741 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import java.util.Optional;
import java.util.function.Predicate;
import software.amazon.smithy.aws.traits.protocols.Ec2QueryNameTrait;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.go.codegen.knowledge.GoPointableIndex;
import software.amazon.smithy.model.shapes.CollectionShape;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
import software.amazon.smithy.model.traits.XmlNameTrait;
Expand Down Expand Up @@ -51,6 +55,14 @@ protected String getSerializedLocationName(MemberShape memberShape, String defau
.orElse(defaultValue));
}

// EC2Query specifically does not serialize non-nil, empty lists
protected void serializeCollection(GenerationContext context, CollectionShape shape) {
context.getWriter().get()
.write("if len(v) == 0 { return nil }");

super.serializeCollection(context, shape);
}

@Override
protected boolean isFlattened(GenerationContext context, MemberShape memberShape) {
// All lists, sets, and maps are flattened in aws.ec2.
Expand Down
9 changes: 9 additions & 0 deletions internal/protocoltest/ec2query/serializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 20c1ea1

Please sign in to comment.