Skip to content

chore: remove variables from xml serializeMap #1174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions clients/client-s3-control/protocols/Aws_restXml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2622,8 +2622,7 @@ const serializeAws_restXmlS3UserMetadata = (
input: { [key: string]: string },
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Object.keys(input).forEach(key => {
return Object.keys(input).map(key => {
const entryNode = new __XmlNode("entry");
const keyNode = new __XmlNode("NonEmptyMaxLength1024String")
.addChildNode(new __XmlText(key))
Expand All @@ -2633,9 +2632,8 @@ const serializeAws_restXmlS3UserMetadata = (
new __XmlText(input[key])
);
entryNode.addChildNode(node.withName("value"));
collectedNodes.push(entryNode);
return entryNode;
});
return collectedNodes;
};

const serializeAws_restXmlVpcConfiguration = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ protected void serializeMap(GenerationContext context, MapShape shape) {
Model model = context.getModel();
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");

// Set up a location to store all of the child node(s).
writer.write("const collectedNodes: any = [];");
// Use the keys as an iteration point to dispatch to the input value providers.
writer.openBlock("Object.keys(input).forEach(key => {", "});", () -> {
writer.openBlock("return Object.keys(input).map(key => {", "});", () -> {
// Prepare a containing node for each entry's k/v pair.
writer.write("const entryNode = new __XmlNode(\"entry\");");

Expand All @@ -137,25 +135,23 @@ protected void serializeMap(GenerationContext context, MapShape shape) {
writer.write("const node = $L;", valueTarget.accept(getMemberVisitor("input[key]")));
// Handle proper unwrapping of target nodes.
if (serializationReturnsArray(valueTarget)) {
writer.write("const container = new __XmlNode($S);", valueName);
writer.openBlock("for (let index in node) {", "}", () -> {
writer.write("const workingNode = node[index];");
// Add @xmlNamespace value of the value member.
AwsProtocolUtils.writeXmlNamespace(context, valueMember, "workingNode");
writer.write("container.addChildNode(workingNode);");
writer.openBlock("entryNode.addChildNode(", ");", () -> {
writer.openBlock("node.reduce((acc: __XmlNode, workingNode: any) => {", "}", () -> {
// Add @xmlNamespace value of the value member.
AwsProtocolUtils.writeXmlNamespace(context, valueMember, "workingNode");
writer.write("acc.addChildNode(workingNode);");
writer.write("return acc;");
});
writer.write(", new __XmlNode($S));", valueName);
});
writer.write("entryNode.addChildNode(container);");
} else {
// Add @xmlNamespace value of the target member.
AwsProtocolUtils.writeXmlNamespace(context, valueMember, "node");
writer.write("entryNode.addChildNode(node.withName($S));", valueName);
}

// Add the entry to the collection.
writer.write("collectedNodes.push(entryNode);");
writer.write("return entryNode;");
});

writer.write("return collectedNodes;");
}

@Override
Expand Down
24 changes: 8 additions & 16 deletions protocol_tests/aws-restxml/protocols/Aws_restXml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4115,8 +4115,7 @@ const serializeAws_restXmlFlattenedXmlMapWithXmlNameInputOutputMap = (
input: { [key: string]: string },
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Object.keys(input).forEach(key => {
return Object.keys(input).map(key => {
const entryNode = new __XmlNode("entry");
const keyNode = new __XmlNode("String")
.addChildNode(new __XmlText(key))
Expand All @@ -4126,9 +4125,8 @@ const serializeAws_restXmlFlattenedXmlMapWithXmlNameInputOutputMap = (
new __XmlText(input[key])
);
entryNode.addChildNode(node.withName("V"));
collectedNodes.push(entryNode);
return entryNode;
});
return collectedNodes;
};

const serializeAws_restXmlNestedPayload = (
Expand Down Expand Up @@ -4300,36 +4298,32 @@ const serializeAws_restXmlXmlMapsInputOutputMap = (
input: { [key: string]: GreetingStruct },
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Object.keys(input).forEach(key => {
return Object.keys(input).map(key => {
const entryNode = new __XmlNode("entry");
const keyNode = new __XmlNode("String")
.addChildNode(new __XmlText(key))
.withName("key");
entryNode.addChildNode(keyNode);
const node = serializeAws_restXmlGreetingStruct(input[key], context);
entryNode.addChildNode(node.withName("value"));
collectedNodes.push(entryNode);
return entryNode;
});
return collectedNodes;
};

const serializeAws_restXmlXmlMapsXmlNameInputOutputMap = (
input: { [key: string]: GreetingStruct },
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Object.keys(input).forEach(key => {
return Object.keys(input).map(key => {
const entryNode = new __XmlNode("entry");
const keyNode = new __XmlNode("String")
.addChildNode(new __XmlText(key))
.withName("Attribute");
entryNode.addChildNode(keyNode);
const node = serializeAws_restXmlGreetingStruct(input[key], context);
entryNode.addChildNode(node.withName("Setting"));
collectedNodes.push(entryNode);
return entryNode;
});
return collectedNodes;
};

const serializeAws_restXmlXmlNamespaceNested = (
Expand Down Expand Up @@ -4399,8 +4393,7 @@ const serializeAws_restXmlFooEnumMap = (
input: { [key: string]: FooEnum | string },
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Object.keys(input).forEach(key => {
return Object.keys(input).map(key => {
const entryNode = new __XmlNode("entry");
const keyNode = new __XmlNode("String")
.addChildNode(new __XmlText(key))
Expand All @@ -4410,9 +4403,8 @@ const serializeAws_restXmlFooEnumMap = (
new __XmlText(input[key])
);
entryNode.addChildNode(node.withName("value"));
collectedNodes.push(entryNode);
return entryNode;
});
return collectedNodes;
};

const serializeAws_restXmlFooEnumSet = (
Expand Down