Skip to content

Commit 75365e0

Browse files
committed
chore: remove wrappedItem
1 parent 36a26c8 commit 75365e0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ protected void deserializeCollection(GenerationContext context, CollectionShape
6868
// Dispatch to the output value provider for any additional handling.
6969
writer.write("const contents: any = [];");
7070
writer.openBlock("(output || []).map((entry: any) => {", "});", () -> {
71-
String dataSource = handleUnnamedTargetWrapping(context, target, "entry");
71+
String dataSource = getUnnamedTargetWrapper(context, target, "entry");
7272
writer.write("contents.push($L);", target.accept(getMemberVisitor(dataSource)));
7373
});
7474
writer.write("return contents;");
7575
}
7676

77-
private String handleUnnamedTargetWrapping(GenerationContext context, Shape target, String dataSource) {
77+
private String getUnnamedTargetWrapper(GenerationContext context, Shape target, String dataSource) {
7878
if (!deserializationReturnsArray(target)) {
7979
return dataSource;
8080
}
@@ -85,8 +85,7 @@ private String handleUnnamedTargetWrapping(GenerationContext context, Shape targ
8585
// return multiple entries but only has one.
8686
// Update the target element if we target another level of collection.
8787
String targetLocation = getUnnamedAggregateTargetLocation(context.getModel(), target);
88-
writer.write("const wrappedItem = __getArrayIfSingleItem($1L[$2S]);", dataSource, targetLocation);
89-
return "wrappedItem";
88+
return String.format("__getArrayIfSingleItem(%s[\"%s\"])", dataSource, targetLocation);
9089
}
9190

9291
private boolean deserializationReturnsArray(Shape shape) {
@@ -112,7 +111,7 @@ protected void deserializeMap(GenerationContext context, MapShape shape) {
112111
writer.write("const mapParams: any = {};");
113112
writer.openBlock("output.forEach((pair: any) => {", "});", () -> {
114113
// Dispatch to the output value provider for any additional handling.
115-
String dataSource = handleUnnamedTargetWrapping(context, target, "pair[\"" + valueLocation + "\"]");
114+
String dataSource = getUnnamedTargetWrapper(context, target, "pair[\"" + valueLocation + "\"]");
116115
writer.write("mapParams[pair[$S]] = $L;", keyLocation, target.accept(getMemberVisitor(dataSource)));
117116
});
118117
writer.write("return mapParams;");
@@ -212,12 +211,12 @@ void deserializeNamedMember(
212211
.map(location -> location + " !== undefined")
213212
.collect(Collectors.joining(" && "));
214213
writer.openBlock("if ($L) {", "}", validationStatement, () -> {
215-
String dataSource = handleNamedTargetWrapping(context, target, source);
214+
String dataSource = getNamedTargetWrapper(context, target, source);
216215
statementBodyGenerator.accept(dataSource, getMemberVisitor(dataSource));
217216
});
218217
}
219218

220-
private String handleNamedTargetWrapping(GenerationContext context, Shape target, String dataSource) {
219+
private String getNamedTargetWrapper(GenerationContext context, Shape target, String dataSource) {
221220
if (!deserializationReturnsArray(target)) {
222221
return dataSource;
223222
}
@@ -226,8 +225,7 @@ private String handleNamedTargetWrapping(GenerationContext context, Shape target
226225
writer.addImport("getArrayIfSingleItem", "__getArrayIfSingleItem", "@aws-sdk/smithy-client");
227226
// The XML parser will set one K:V for a member that could
228227
// return multiple entries but only has one.
229-
writer.write("const wrappedItem = __getArrayIfSingleItem($1L)", dataSource);
230-
return "wrappedItem";
228+
return String.format("__getArrayIfSingleItem(%s)", dataSource);
231229
}
232230

233231
private String getUnnamedAggregateTargetLocation(Model model, Shape shape) {

0 commit comments

Comments
 (0)