Skip to content

Commit c65c30c

Browse files
committed
chore: remove bodyParams from restJson serInputDocument
1 parent 5f820e6 commit c65c30c

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import software.amazon.smithy.model.shapes.Shape;
2525
import software.amazon.smithy.model.shapes.StructureShape;
2626
import software.amazon.smithy.model.shapes.UnionShape;
27+
import software.amazon.smithy.model.traits.IdempotencyTokenTrait;
2728
import software.amazon.smithy.model.traits.JsonNameTrait;
2829
import software.amazon.smithy.model.traits.TimestampFormatTrait;
2930
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
@@ -102,35 +103,31 @@ public void serializeInputDocument(
102103

103104
SymbolProvider symbolProvider = context.getSymbolProvider();
104105

105-
writer.write("const bodyParams: any = {};");
106-
for (HttpBinding binding : documentBindings) {
107-
MemberShape memberShape = binding.getMember();
108-
// The name of the member to get from the input shape.
109-
String memberName = symbolProvider.toMemberName(memberShape);
110-
String inputLocation = "input." + memberName;
111-
// Use the jsonName trait value if present, otherwise use the member name.
112-
String locationName = memberShape.getTrait(JsonNameTrait.class)
113-
.map(JsonNameTrait::getValue)
114-
.orElseGet(binding::getLocationName);
115-
Shape target = context.getModel().expectShape(memberShape.getTarget());
116-
117-
// Handle if the member is an idempotency token that should be auto-filled.
118-
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
119-
120-
// Generate an if statement to set the bodyParam if the member is set.
121-
writer.openBlock("if ($L !== undefined) {", "}", inputLocation, () -> {
106+
writer.openBlock("body = JSON.stringify({", "});", () -> {
107+
for (HttpBinding binding : documentBindings) {
108+
MemberShape memberShape = binding.getMember();
109+
// The name of the member to get from the input shape.
110+
String memberName = symbolProvider.toMemberName(memberShape);
111+
String inputLocation = "input." + memberName;
112+
// Use the jsonName trait value if present, otherwise use the member name.
113+
String locationName = memberShape.getTrait(JsonNameTrait.class)
114+
.map(JsonNameTrait::getValue)
115+
.orElseGet(binding::getLocationName);
116+
Shape target = context.getModel().expectShape(memberShape.getTarget());
117+
122118
// Handle @timestampFormat on members not just the targeted shape.
123119
String valueProvider = memberShape.hasTrait(TimestampFormatTrait.class)
124120
? AwsProtocolUtils.getInputTimestampValueProvider(context, memberShape,
125121
getDocumentTimestampFormat(), inputLocation)
126122
: target.accept(getMemberSerVisitor(context, inputLocation));
127123

128-
// Dispatch to the input value provider for any additional handling.
129-
writer.write("bodyParams['$L'] = $L;", locationName, valueProvider);
130-
});
131-
}
132-
133-
writer.write("body = JSON.stringify(bodyParams);");
124+
if (memberShape.hasTrait(IdempotencyTokenTrait.class)) {
125+
writer.write("'$L': $L ?? generateIdempotencyToken(),", locationName, valueProvider);
126+
} else {
127+
writer.write("...($L !== undefined && { '$L': $L }),", inputLocation, locationName, valueProvider);
128+
}
129+
}
130+
});
134131
}
135132

136133
@Override

0 commit comments

Comments
 (0)