Skip to content

Commit ebc70f9

Browse files
committed
Fix issue parsing lists of HTTP_DATE timestamps
1 parent f16ee81 commit ebc70f9

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,28 @@ private String getCollectionOutputParam(
13721372
targetMember, collectionTarget);
13731373
switch (bindingType) {
13741374
case HEADER:
1375+
dataSource = "(" + dataSource + " || \"\")";
13751376
// Split these values on commas.
1376-
String outputParam = "(" + dataSource + " || \"\").split(',').map(_entry => "
1377-
+ collectionTargetValue + ")";
1377+
String outputParam = "" + dataSource + ".split(',')";
1378+
1379+
// Headers that have HTTP_DATE formatted timestamps already contain a ","
1380+
// in their formatted entry, so split on every other "," instead.
1381+
if (collectionTarget.isTimestampShape()) {
1382+
// Check if our member resolves to the HTTP_DATE format.
1383+
HttpBindingIndex httpIndex = context.getModel().getKnowledge(HttpBindingIndex.class);
1384+
Format format = httpIndex.determineTimestampFormat(targetMember, bindingType, Format.HTTP_DATE);
1385+
1386+
if (format == Format.HTTP_DATE) {
1387+
TypeScriptWriter writer = context.getWriter();
1388+
writer.addImport("splitEvery", "__splitEvery", "@aws-sdk/smithy-client");
1389+
outputParam = "__splitEvery(" + dataSource + ", ',', 2)";
1390+
}
1391+
}
1392+
1393+
// Iterate over each entry and do deser work.
1394+
outputParam += ".map(_entry => " + collectionTargetValue + ")";
1395+
1396+
// Make sets when necessary.
13781397
if (target.isSetShape()) {
13791398
outputParam = "new Set(" + outputParam + ")";
13801399
}

0 commit comments

Comments
 (0)