From ad2fa4e644d66d1bc2b54c20a0ce0fce7a6cf2b8 Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Sun, 5 Jun 2022 05:04:40 +0000 Subject: [PATCH] chore: skip serializing members with eventHeader trait --- .../aws/typescript/codegen/AwsRestXml.java | 2 -- .../codegen/JsonShapeSerVisitor.java | 19 +++++++++++++------ .../codegen/RestJsonProtocolGenerator.java | 1 - .../codegen/XmlShapeSerVisitor.java | 9 ++++++++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java index 91b22f17e9e7d..51faf11258fa3 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java @@ -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); diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java index 1de98b4e42f47..9d1ddf006ce90 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java @@ -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; @@ -138,6 +139,9 @@ public void serializeStructure(GenerationContext context, StructureShape shape) // Use a TreeMap to sort the members. Map 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; @@ -170,12 +174,15 @@ public void serializeUnion(GenerationContext context, UnionShape shape) { // Use a TreeMap to sort the members. Map 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)"); }); } diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java index 1d343586f4750..c673b9e0c53d2 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java @@ -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(); diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlShapeSerVisitor.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlShapeSerVisitor.java index c03da0191eff4..349eaf78671bf 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlShapeSerVisitor.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlShapeSerVisitor.java @@ -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; @@ -200,8 +201,11 @@ protected void serializeStructure(GenerationContext context, StructureShape shap // Serialize every member of the structure if present. Map 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); @@ -318,6 +322,9 @@ protected void serializeUnion(GenerationContext context, UnionShape shape) { writer.openBlock("$L.visit(input, {", "});", shape.getId().getName(serviceShape), () -> { Map members = shape.getAllMembers(); members.forEach((memberName, memberShape) -> { + if (memberShape.hasTrait(EventHeaderTrait.class)) { + return; + } writer.openBlock("$L: value => {", "},", memberName, () -> { serializeNamedMember(context, memberName, memberShape, () -> "value"); });