Skip to content

Commit 33dc34a

Browse files
authored
fix: event stream serialization (#1674)
1 parent 5334f29 commit 33dc34a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private void writeEventBody(
387387
writer.write("body = input.$L;", payloadMemberName);
388388
} else if (payloadShape instanceof StringShape) {
389389
writer.write("body = context.utf8Decoder(input.$L);", payloadMemberName);
390-
} else if (payloadShape instanceof BlobShape || payloadShape instanceof StringShape) {
390+
} else if (payloadShape instanceof StructureShape || payloadShape instanceof UnionShape) {
391391
Symbol symbol = getSymbol(context, payloadShape);
392392
String serFunctionName = ProtocolGenerator.getSerFunctionShortName(symbol);
393393
boolean mayElide = serdeElisionIndex.mayElide(payloadShape);

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
3535
import software.amazon.smithy.typescript.codegen.knowledge.SerdeElisionIndex;
3636
import software.amazon.smithy.utils.OptionalUtils;
37+
import software.amazon.smithy.utils.SmithyInternalApi;
3738
import software.amazon.smithy.utils.SmithyUnstableApi;
3839

3940
/**
@@ -107,7 +108,7 @@ public void generateSharedComponents(GenerationContext context) {
107108
getDocumentContentType(),
108109
() -> {
109110
TypeScriptWriter writer = context.getWriter();
110-
writer.write("body = context.utf8Decoder(body);");
111+
serializeEventStreamBodyToBytes(writer);
111112
},
112113
serializingDocumentShapes
113114
);
@@ -606,6 +607,17 @@ protected String getErrorBodyLocation(GenerationContext context, String outputLo
606607
return outputLocation;
607608
}
608609

610+
/**
611+
* Allows RPC protocols to designate how to convert the body into bytes.
612+
*
613+
* @deprecated superseded by schema-serde.
614+
*/
615+
@Deprecated
616+
@SmithyInternalApi
617+
protected void serializeEventStreamBodyToBytes(TypeScriptWriter writer) {
618+
writer.write("body = context.utf8Decoder(JSON.stringify(body));");
619+
}
620+
609621
/**
610622
* Writes the code needed to deserialize the output document of a response.
611623
*

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/protocols/cbor/SmithyRpcV2Cbor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public void generateSharedComponents(GenerationContext context) {
6767
service,
6868
getDocumentContentType(),
6969
() -> {
70-
writer.write("body = context.utf8Decoder(body);");
70+
writer.addImportSubmodule(
71+
"cbor", null,
72+
TypeScriptDependency.SMITHY_CORE, SmithyCoreSubmodules.CBOR
73+
);
74+
writer.write("body = cbor.encode(body);");
7175
},
7276
serializingDocumentShapes
7377
);

0 commit comments

Comments
 (0)