Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen: Update Query Protocol generation to always serialized unboxed #1161

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,9 @@
{
"ID": "service.ec2-bugfix-1615341031066265000",
"SchemaVersion": 1,
"Module": "service/ec2",
"Type": "bugfix",
"Description": "Fixes Amazon EC2 serialization of unboxed members, to serialize zero values in request messages.",
"MinVersion": "",
"AffectedModules": null
}
Expand Up @@ -4,10 +4,12 @@
import java.util.function.Predicate;
import software.amazon.smithy.aws.traits.protocols.Ec2QueryNameTrait;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.go.codegen.trait.NoSerializeTrait;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
import software.amazon.smithy.model.traits.XmlNameTrait;
import software.amazon.smithy.utils.FunctionalUtils;
import software.amazon.smithy.utils.StringUtils;

/**
Expand All @@ -29,11 +31,11 @@
*/
final class Ec2QueryShapeSerVisitor extends QueryShapeSerVisitor {
public Ec2QueryShapeSerVisitor(GenerationContext context) {
super(context);
this(context, NoSerializeTrait.excludeNoSerializeMembers().and(FunctionalUtils.alwaysTrue()));
}

public Ec2QueryShapeSerVisitor(GenerationContext context, Predicate<MemberShape> memberFilter) {
super(context, memberFilter);
super(context, memberFilter, true);
}

@Override
Expand Down
Expand Up @@ -15,7 +15,6 @@
import software.amazon.smithy.go.codegen.SymbolUtils;
import software.amazon.smithy.go.codegen.integration.DocumentShapeSerVisitor;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.go.codegen.integration.ProtocolUtils;
import software.amazon.smithy.go.codegen.knowledge.GoPointableIndex;
import software.amazon.smithy.go.codegen.trait.NoSerializeTrait;
import software.amazon.smithy.model.shapes.CollectionShape;
Expand All @@ -25,7 +24,6 @@
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.traits.EnumTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
import software.amazon.smithy.model.traits.XmlFlattenedTrait;
Expand All @@ -46,14 +44,20 @@ class QueryShapeSerVisitor extends DocumentShapeSerVisitor {
private static final Logger LOGGER = Logger.getLogger(QueryShapeSerVisitor.class.getName());

private final Predicate<MemberShape> memberFilter;
private final boolean serializeZeroUnboxedMember;

public QueryShapeSerVisitor(GenerationContext context) {
this(context, NoSerializeTrait.excludeNoSerializeMembers().and(FunctionalUtils.alwaysTrue()));
}

public QueryShapeSerVisitor(GenerationContext context, Predicate<MemberShape> memberFilter) {
this(context, memberFilter, false);
}

public QueryShapeSerVisitor(GenerationContext context, Predicate<MemberShape> memberFilter, boolean serializeZeroUnboxedMember) {
super(context);
this.memberFilter = NoSerializeTrait.excludeNoSerializeMembers().and(memberFilter);
this.serializeZeroUnboxedMember = serializeZeroUnboxedMember;
}

private DocumentMemberSerVisitor getMemberSerVisitor(MemberShape member, String source, String dest) {
Expand Down Expand Up @@ -156,7 +160,7 @@ protected void serializeStructure(GenerationContext context, StructureShape shap
Shape target = context.getModel().expectShape(member.getTarget());

GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
member, "v", true, member.isRequired(), (operand) -> {
member, "v", true, member.isRequired() || this.serializeZeroUnboxedMember, (operand) -> {
String locationName = getSerializedLocationName(member, member.getMemberName());
if (isFlattened(context, member)) {
writer.write("objectKey := object.FlatKey($S)", locationName);
Expand Down