Skip to content

Commit

Permalink
codegen: Update Query Protocol generation to always serialized unboxed.
Browse files Browse the repository at this point in the history
Updates the Query Protocol serializer generation to always serialize
unboxed member values to the querystring. This prevents issues with
members values never being serialized to the request.

Fixes aws#1107
  • Loading branch information
jasdel committed Mar 10, 2021
1 parent c122f49 commit 7c83027
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7c83027

Please sign in to comment.