Skip to content

Commit fe92f4b

Browse files
committed
fix(codegen): replace decodeEscapedXML with decode from he
1 parent ccf2d3f commit fe92f4b

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public enum AwsDependency implements SymbolDependencyContainer {
5555
BODY_CHECKSUM_GENERATOR_NODE(NORMAL_DEPENDENCY, "@aws-sdk/body-checksum-node", "3.13.1"),
5656
XML_BUILDER(NORMAL_DEPENDENCY, "@aws-sdk/xml-builder", "3.14.0"),
5757
XML_PARSER(NORMAL_DEPENDENCY, "fast-xml-parser", "3.19.0"),
58+
HTML_ENTITIES(NORMAL_DEPENDENCY, "he", "1.2.0"),
59+
TYPES_HTML_ENTITIES(DEV_DEPENDENCY, "@types/he", "1.1.1"),
5860
UUID_GENERATOR(NORMAL_DEPENDENCY, "uuid", "^8.3.2"),
5961
UUID_GENERATOR_TYPES(DEV_DEPENDENCY, "@types/uuid", "^8.3.0"),
6062
MIDDLEWARE_EVENTSTREAM(NORMAL_DEPENDENCY, "@aws-sdk/middleware-eventstream", "3.13.1"),

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
3737
import software.amazon.smithy.typescript.codegen.integration.HttpProtocolGeneratorUtils;
3838
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator.GenerationContext;
39-
import software.amazon.smithy.utils.IoUtils;
4039
import software.amazon.smithy.utils.SmithyInternalApi;
4140

4241
/**
@@ -120,21 +119,20 @@ static void generateJsonParseBody(GenerationContext context) {
120119
static void generateXmlParseBody(GenerationContext context) {
121120
TypeScriptWriter writer = context.getWriter();
122121

123-
// Include function that decodes XML escape characters.
124-
writer.write(IoUtils.readUtf8Resource(AwsProtocolUtils.class, "decodeEscapedXML.ts"));
125-
126122
// Include an XML body parser used to deserialize documents from HTTP responses.
127123
writer.addImport("SerdeContext", "__SerdeContext", "@aws-sdk/types");
128124
writer.addImport("getValueFromTextNode", "__getValueFromTextNode", "@aws-sdk/smithy-client");
129125
writer.addDependency(AwsDependency.XML_PARSER);
126+
writer.addDependency(AwsDependency.HTML_ENTITIES);
127+
writer.addDependency(AwsDependency.TYPES_HTML_ENTITIES);
130128
writer.addImport("parse", "xmlParse", "fast-xml-parser");
129+
writer.addImport("decode", "heDecode", "he");
131130
writer.openBlock("const parseBody = (streamBody: any, context: __SerdeContext): "
132131
+ "any => collectBodyString(streamBody, context).then(encoded => {", "});", () -> {
133132
writer.openBlock("if (encoded.length) {", "}", () -> {
134133
writer.write("const parsedObj = xmlParse(encoded, { attributeNamePrefix: '', "
135134
+ "ignoreAttributes: false, parseNodeValue: false, trimValues: false, "
136-
+ "tagValueProcessor: (val, tagName) => val.trim() === '' ? "
137-
+ "'': decodeEscapedXML(val) });");
135+
+ "tagValueProcessor: (val, tagName) => val.trim() === '' ? '': heDecode(val) });");
138136
writer.write("const textNodeName = '#text';");
139137
writer.write("const key = Object.keys(parsedObj)[0];");
140138
writer.write("const parsedObjToReturn = parsedObj[key];");

codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/decodeEscapedXML.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)