Skip to content

Commit c9bd6b1

Browse files
committed
chore: remove bodyParams from json serializeStructure
1 parent 5f820e6 commit c9bd6b1

File tree

1 file changed

+20
-23
lines changed
  • codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen

1 file changed

+20
-23
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import software.amazon.smithy.model.shapes.Shape;
2626
import software.amazon.smithy.model.shapes.StructureShape;
2727
import software.amazon.smithy.model.shapes.UnionShape;
28+
import software.amazon.smithy.model.traits.IdempotencyTokenTrait;
2829
import software.amazon.smithy.model.traits.JsonNameTrait;
2930
import software.amazon.smithy.model.traits.TimestampFormatTrait;
3031
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
@@ -88,35 +89,31 @@ public void serializeMap(GenerationContext context, MapShape shape) {
8889
public void serializeStructure(GenerationContext context, StructureShape shape) {
8990
TypeScriptWriter writer = context.getWriter();
9091

91-
writer.write("const bodyParams: any = {};");
92-
// Use a TreeMap to sort the members.
93-
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
94-
members.forEach((memberName, memberShape) -> {
95-
// Use the jsonName trait value if present, otherwise use the member name.
96-
String locationName = memberShape.getTrait(JsonNameTrait.class)
97-
.map(JsonNameTrait::getValue)
98-
.orElse(memberName);
99-
Shape target = context.getModel().expectShape(memberShape.getTarget());
100-
String inputLocation = "input." + memberName;
101-
102-
// Handle if the member is an idempotency token that should be auto-filled.
103-
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
104-
105-
// Generate an if statement to set the bodyParam if the member is set.
106-
writer.openBlock("if ($L !== undefined) {", "}", inputLocation, () -> {
107-
String dataSource = "input." + memberName;
92+
writer.openBlock("return {", "};", () -> {
93+
// Use a TreeMap to sort the members.
94+
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
95+
members.forEach((memberName, memberShape) -> {
96+
// Use the jsonName trait value if present, otherwise use the member name.
97+
String locationName = memberShape.getTrait(JsonNameTrait.class)
98+
.map(JsonNameTrait::getValue)
99+
.orElse(memberName);
100+
Shape target = context.getModel().expectShape(memberShape.getTarget());
101+
String inputLocation = "input." + memberName;
108102

109103
// Handle @timestampFormat on members not just the targeted shape.
110104
String valueProvider = memberShape.hasTrait(TimestampFormatTrait.class)
111105
? AwsProtocolUtils.getInputTimestampValueProvider(context, memberShape,
112-
TIMESTAMP_FORMAT, dataSource)
113-
: target.accept(getMemberVisitor(dataSource));
114-
115-
// Dispatch to the input value provider for any additional handling.
116-
writer.write("bodyParams['$L'] = $L;", locationName, valueProvider);
106+
TIMESTAMP_FORMAT, inputLocation)
107+
: target.accept(getMemberVisitor(inputLocation));
108+
109+
if (memberShape.hasTrait(IdempotencyTokenTrait.class)) {
110+
writer.write("'$L': $L ?? generateIdempotencyToken(),", locationName, valueProvider);
111+
} else {
112+
writer.write("...($L !== undefined && { '$L': $L }),", inputLocation, locationName, valueProvider);
113+
}
117114
});
115+
118116
});
119-
writer.write("return bodyParams;");
120117
}
121118

122119
@Override

0 commit comments

Comments
 (0)