Skip to content

Commit

Permalink
chore: skip serializing members with eventHeader trait
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jun 5, 2022
1 parent 0c8d05c commit ad2fa4e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ protected void serializeInputEventDocumentPayload(
Shape payloadShape
) {
TypeScriptWriter writer = context.getWriter();
Model model = context.getModel();

if (payloadShape instanceof StructureShape || payloadShape instanceof UnionShape) {
SymbolProvider symbolProvider = context.getSymbolProvider();
Symbol symbol = symbolProvider.toSymbol(payloadShape);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.EventHeaderTrait;
import software.amazon.smithy.model.traits.IdempotencyTokenTrait;
import software.amazon.smithy.model.traits.JsonNameTrait;
import software.amazon.smithy.model.traits.SparseTrait;
Expand Down Expand Up @@ -138,6 +139,9 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
// Use a TreeMap to sort the members.
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
members.forEach((memberName, memberShape) -> {
if (memberShape.hasTrait(EventHeaderTrait.class)) {
return;
}
String locationName = memberNameStrategy.apply(memberShape, memberName);
Shape target = context.getModel().expectShape(memberShape.getTarget());
String inputLocation = "input." + memberName;
Expand Down Expand Up @@ -170,12 +174,15 @@ public void serializeUnion(GenerationContext context, UnionShape shape) {
// Use a TreeMap to sort the members.
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
members.forEach((memberName, memberShape) -> {
String locationName = memberNameStrategy.apply(memberShape, memberName);
Shape target = model.expectShape(memberShape.getTarget());
// Dispatch to the input value provider for any additional handling.
writer.write("$L: value => ({ $S: $L }),", memberName, locationName,
target.accept(getMemberVisitor("value")));
});
if (memberShape.hasTrait(EventHeaderTrait.class)) {
return;
}
String locationName = memberNameStrategy.apply(memberShape, memberName);
Shape target = model.expectShape(memberShape.getTarget());
// Dispatch to the input value provider for any additional handling.
writer.write("$L: value => ({ $S: $L }),", memberName, locationName,
target.accept(getMemberVisitor("value")));
});
writer.write("_: (name, value) => ({ name: value } as any)");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ protected void serializeInputEventDocumentPayload(
Shape payloadShape
) {
TypeScriptWriter writer = context.getWriter();
Model model = context.getModel();

if (payloadShape instanceof StructureShape || payloadShape instanceof UnionShape) {
SymbolProvider symbolProvider = context.getSymbolProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.EventHeaderTrait;
import software.amazon.smithy.model.traits.SparseTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
Expand Down Expand Up @@ -200,8 +201,11 @@ protected void serializeStructure(GenerationContext context, StructureShape shap
// Serialize every member of the structure if present.
Map<String, MemberShape> members = shape.getAllMembers();
members.forEach((memberName, memberShape) -> {
String inputLocation = "input." + memberName;
if (memberShape.hasTrait(EventHeaderTrait.class)) {
return;
}

String inputLocation = "input." + memberName;
// Handle if the member is an idempotency token that should be auto-filled.
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);

Expand Down Expand Up @@ -318,6 +322,9 @@ protected void serializeUnion(GenerationContext context, UnionShape shape) {
writer.openBlock("$L.visit(input, {", "});", shape.getId().getName(serviceShape), () -> {
Map<String, MemberShape> members = shape.getAllMembers();
members.forEach((memberName, memberShape) -> {
if (memberShape.hasTrait(EventHeaderTrait.class)) {
return;
}
writer.openBlock("$L: value => {", "},", memberName, () -> {
serializeNamedMember(context, memberName, memberShape, () -> "value");
});
Expand Down

0 comments on commit ad2fa4e

Please sign in to comment.