Skip to content

Commit fce4efe

Browse files
committed
chore: call writeIdempotencyAutofill in a separate loop
1 parent 1bd0678 commit fce4efe

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ protected void serializeInputDocument(
150150
}
151151

152152
SymbolProvider symbolProvider = context.getSymbolProvider();
153+
154+
for (HttpBinding binding : documentBindings) {
155+
MemberShape memberShape = binding.getMember();
156+
// The name of the member to get from the input shape.
157+
String memberName = symbolProvider.toMemberName(memberShape);
158+
String inputLocation = "input." + memberName;
159+
160+
// Handle if the member is an idempotency token that should be auto-filled.
161+
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
162+
}
163+
153164
ShapeId inputShapeId = documentBindings.get(0).getMember().getContainer();
154165

155166
// Start with the XML declaration.
@@ -174,9 +185,6 @@ protected void serializeInputDocument(
174185
String memberName = symbolProvider.toMemberName(memberShape);
175186
String inputLocation = "input." + memberName;
176187

177-
// Handle if the member is an idempotency token that should be auto-filled.
178-
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
179-
180188
writer.openBlock("if ($L !== undefined) {", "}", inputLocation, () -> {
181189
shapeSerVisitor.serializeNamedMember(context, memberName, memberShape, () -> inputLocation);
182190
});

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ public void serializeMap(GenerationContext context, MapShape shape) {
9090
public void serializeStructure(GenerationContext context, StructureShape shape) {
9191
TypeScriptWriter writer = context.getWriter();
9292

93-
writer.write("const bodyParams: any = {};");
9493
// Use a TreeMap to sort the members.
9594
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
95+
96+
members.forEach((memberName, memberShape) -> {
97+
String inputLocation = "input." + memberName;
98+
// Handle if the member is an idempotency token that should be auto-filled.
99+
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
100+
});
101+
102+
writer.write("const bodyParams: any = {};");
96103
members.forEach((memberName, memberShape) -> {
97104
// Use the jsonName trait value if present, otherwise use the member name.
98105
String locationName = memberShape.getTrait(JsonNameTrait.class)
@@ -101,9 +108,6 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
101108
Shape target = context.getModel().expectShape(memberShape.getTarget());
102109
String inputLocation = "input." + memberName;
103110

104-
// Handle if the member is an idempotency token that should be auto-filled.
105-
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
106-
107111
// Generate an if statement to set the bodyParam if the member is set.
108112
writer.openBlock("if ($L !== undefined) {", "}", inputLocation, () -> {
109113
String dataSource = "input." + memberName;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,18 @@ private void serializeUnnamedMemberEntryList(
143143
protected void serializeStructure(GenerationContext context, StructureShape shape) {
144144
TypeScriptWriter writer = context.getWriter();
145145

146+
shape.getAllMembers().forEach((memberName, memberShape) -> {
147+
String inputLocation = "input." + memberName;
148+
// Handle if the member is an idempotency token that should be auto-filled.
149+
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
150+
});
151+
146152
// Set up a location to store all of the entry pairs.
147153
writer.write("const entries: any = {};");
148154

149155
// Serialize every member of the structure if present.
150156
shape.getAllMembers().forEach((memberName, memberShape) -> {
151157
String inputLocation = "input." + memberName;
152-
153-
// Handle if the member is an idempotency token that should be auto-filled.
154-
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
155-
156158
writer.openBlock("if ($L !== undefined) {", "}", inputLocation,
157159
() -> serializeNamedMember(context, memberName, memberShape, inputLocation));
158160
});

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ public void serializeInputDocument(
102102

103103
SymbolProvider symbolProvider = context.getSymbolProvider();
104104

105+
for (HttpBinding binding : documentBindings) {
106+
MemberShape memberShape = binding.getMember();
107+
// The name of the member to get from the input shape.
108+
String memberName = symbolProvider.toMemberName(memberShape);
109+
String inputLocation = "input." + memberName;
110+
111+
// Handle if the member is an idempotency token that should be auto-filled.
112+
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
113+
}
114+
105115
writer.write("const bodyParams: any = {};");
106116
for (HttpBinding binding : documentBindings) {
107117
MemberShape memberShape = binding.getMember();
@@ -114,9 +124,6 @@ public void serializeInputDocument(
114124
.orElseGet(binding::getLocationName);
115125
Shape target = context.getModel().expectShape(memberShape.getTarget());
116126

117-
// Handle if the member is an idempotency token that should be auto-filled.
118-
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
119-
120127
// Generate an if statement to set the bodyParam if the member is set.
121128
writer.openBlock("if ($L !== undefined) {", "}", inputLocation, () -> {
122129
// Handle @timestampFormat on members not just the targeted shape.

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,23 @@ protected void serializeStructure(GenerationContext context, StructureShape shap
168168
.map(XmlNameTrait::getValue)
169169
.orElse(shape.getId().getName());
170170

171-
// Create the structure's node.
172-
writer.write("const bodyNode = new __XmlNode($S);", nodeName);
173-
174171
// Serialize every member of the structure if present.
175172
Map<String, MemberShape> members = shape.getAllMembers();
173+
176174
members.forEach((memberName, memberShape) -> {
177175
String inputLocation = "input." + memberName;
178-
179176
// Handle if the member is an idempotency token that should be auto-filled.
180177
AwsProtocolUtils.writeIdempotencyAutofill(context, memberShape, inputLocation);
178+
});
181179

180+
// Create the structure's node.
181+
writer.write("const bodyNode = new __XmlNode($S);", nodeName);
182+
members.forEach((memberName, memberShape) -> {
183+
String inputLocation = "input." + memberName;
182184
writer.openBlock("if ($L !== undefined) {", "}", inputLocation, () -> {
183185
serializeNamedMember(context, memberName, memberShape, () -> inputLocation);
184186
});
185187
});
186-
187188
writer.write("return bodyNode;");
188189
}
189190

0 commit comments

Comments
 (0)