Skip to content

Commit 0eb60a0

Browse files
Support Smithy 1.9.x (#367)
1 parent 989020b commit 0eb60a0

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,10 @@ public Void arrayNode(ArrayNode node) {
847847
Shape wrapperShape = this.workingShape;
848848
node.getElements().forEach(element -> {
849849
// Swap the working shape to the member of the collection.
850-
this.workingShape = model.expectShape(((CollectionShape) wrapperShape).getMember().getTarget());
850+
// This isn't necessary if the shape is a document.
851+
if (wrapperShape instanceof CollectionShape) {
852+
this.workingShape = model.expectShape(((CollectionShape) wrapperShape).getMember().getTarget());
853+
}
851854
writer.call(() -> element.accept(this)).write("\n");
852855
});
853856
this.workingShape = wrapperShape;
@@ -1039,7 +1042,10 @@ public Void arrayNode(ArrayNode node) {
10391042
Shape wrapperShape = this.workingShape;
10401043
node.getElements().forEach(element -> {
10411044
// Swap the working shape to the member of the collection.
1042-
this.workingShape = model.expectShape(((CollectionShape) wrapperShape).getMember().getTarget());
1045+
// This isn't necessary if the shape is a document.
1046+
if (wrapperShape instanceof CollectionShape) {
1047+
this.workingShape = model.expectShape(((CollectionShape) wrapperShape).getMember().getTarget());
1048+
}
10431049
writer.call(() -> element.accept(this)).write("\n");
10441050
});
10451051
this.workingShape = wrapperShape;
@@ -1134,6 +1140,21 @@ public Void stringNode(StringNode node) {
11341140
// Handle blobs needing to be converted from strings to their input type of UInt8Array.
11351141
if (workingShape.isBlobShape()) {
11361142
writer.write("Uint8Array.from($S, c => c.charCodeAt(0)),", node.getValue());
1143+
} else if (workingShape.isFloatShape() || workingShape.isDoubleShape()) {
1144+
switch (node.getValue()) {
1145+
case "NaN":
1146+
writer.write("NaN,");
1147+
break;
1148+
case "Infinity":
1149+
writer.write("Infinity,");
1150+
break;
1151+
case "-Infinity":
1152+
writer.write("-Infinity,");
1153+
break;
1154+
default:
1155+
throw new CodegenException(String.format(
1156+
"Unexpected string value for `%s`: \"%s\"", workingShape.getId(), node.getValue()));
1157+
}
11371158
} else {
11381159
writer.write("$S,", node.getValue());
11391160
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,24 @@ public String longShape(LongShape shape) {
150150

151151
@Override
152152
public String floatShape(FloatShape shape) {
153-
return expectNumber();
153+
return handleFloat();
154154
}
155155

156156
@Override
157157
public String doubleShape(DoubleShape shape) {
158-
return expectNumber();
158+
return handleFloat();
159159
}
160160

161161
private String expectNumber() {
162162
context.getWriter().addImport("expectNumber", "__expectNumber", "@aws-sdk/smithy-client");
163163
return "__expectNumber(" + dataSource + ")";
164164
}
165165

166+
private String handleFloat() {
167+
context.getWriter().addImport("handleFloat", "__handleFloat", "@aws-sdk/smithy-client");
168+
return "__handleFloat(" + dataSource + ")";
169+
}
170+
166171
@Override
167172
public String stringShape(StringShape shape) {
168173
return HttpProtocolGeneratorUtils.getStringOutputParam(context, shape, dataSource);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,17 @@ public String longShape(LongShape shape) {
148148

149149
@Override
150150
public String floatShape(FloatShape shape) {
151-
return serializeUnmodified();
151+
return handleFloat();
152152
}
153153

154154
@Override
155155
public String doubleShape(DoubleShape shape) {
156-
return serializeUnmodified();
156+
return handleFloat();
157+
}
158+
159+
private String handleFloat() {
160+
context.getWriter().addImport("serializeFloat", "__serializeFloat", "@aws-sdk/smithy-client");
161+
return "__serializeFloat(" + dataSource + ")";
157162
}
158163

159164
@Override

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/integration/DocumentMemberDeserVisitorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public static Collection<Object[]> validMemberTargetTypes() {
7070
return ListUtils.of(new Object[][]{
7171
{BooleanShape.builder().id(id).build(), "__expectBoolean(" + DATA_SOURCE + ")"},
7272
{ByteShape.builder().id(id).build(), "__expectNumber(" + DATA_SOURCE + ")"},
73-
{DoubleShape.builder().id(id).build(), "__expectNumber(" + DATA_SOURCE + ")"},
74-
{FloatShape.builder().id(id).build(), "__expectNumber(" + DATA_SOURCE + ")"},
73+
{DoubleShape.builder().id(id).build(), "__handleFloat(" + DATA_SOURCE + ")"},
74+
{FloatShape.builder().id(id).build(), "__handleFloat(" + DATA_SOURCE + ")"},
7575
{IntegerShape.builder().id(id).build(), "__expectNumber(" + DATA_SOURCE + ")"},
7676
{LongShape.builder().id(id).build(), "__expectNumber(" + DATA_SOURCE + ")"},
7777
{ShortShape.builder().id(id).build(), "__expectNumber(" + DATA_SOURCE + ")"},

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/integration/DocumentMemberSerVisitorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public static Collection<Object[]> validMemberTargetTypes() {
7474
{BigDecimalShape.builder().id(id).build(), DATA_SOURCE + ".toJSON()"},
7575
{BigIntegerShape.builder().id(id).build(), DATA_SOURCE + ".toJSON()"},
7676
{ByteShape.builder().id(id).build(), DATA_SOURCE},
77-
{DoubleShape.builder().id(id).build(), DATA_SOURCE},
78-
{FloatShape.builder().id(id).build(), DATA_SOURCE},
77+
{DoubleShape.builder().id(id).build(), "__serializeFloat(" + DATA_SOURCE + ")"},
78+
{FloatShape.builder().id(id).build(), "__serializeFloat(" + DATA_SOURCE + ")"},
7979
{IntegerShape.builder().id(id).build(), DATA_SOURCE},
8080
{LongShape.builder().id(id).build(), DATA_SOURCE},
8181
{ShortShape.builder().id(id).build(), DATA_SOURCE},

0 commit comments

Comments
 (0)