Skip to content

Commit db67f47

Browse files
committed
Improve complex serialization support
This commit adds support for many new complex serializations. This includes support for HTTP payloads, the prefixHeaders trait, and nested lists, sets, maps, unions, and structures as well as their respective HTTP binding location modifications. It also generalizes the method for generating serde function names across the language.
1 parent 1b4ff49 commit db67f47

File tree

3 files changed

+315
-58
lines changed

3 files changed

+315
-58
lines changed

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import software.amazon.smithy.model.shapes.StructureShape;
2727
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator;
2828
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
29-
import software.amazon.smithy.utils.StringUtils;
3029

3130
/**
3231
* Generates a client command using plugins.
@@ -202,7 +201,7 @@ private void writeSerde() {
202201
.write("protocol: string,")
203202
.write("context: SerdeContext")
204203
.dedent()
205-
.openBlock("): $T {", "}", applicationProtocol.getRequestType(), () -> writeSerdeDispatcher("input"));
204+
.openBlock("): $T {", "}", applicationProtocol.getRequestType(), () -> writeSerdeDispatcher(true));
206205

207206
writer.write("")
208207
.write("private deserialize(")
@@ -211,41 +210,28 @@ private void writeSerde() {
211210
.write("protocol: string,")
212211
.write("context: SerdeContext")
213212
.dedent()
214-
.openBlock("): Promise<$L> {", "}", outputType, () -> writeSerdeDispatcher("output"))
213+
.openBlock("): Promise<$L> {", "}", outputType, () -> writeSerdeDispatcher(false))
215214
.write("");
216215
}
217216

218-
private void writeSerdeDispatcher(String inputOrOutput) {
217+
private void writeSerdeDispatcher(boolean isInput) {
219218
writer.openBlock("switch (protocol) {", "}", () -> {
220219
// Generate case statements for each supported protocol.
221220
// For example:
222221
// case 'aws.rest-json-1.1':
223222
// return getFooCommandAws_RestJson1_1Serialize(input, utils);
224223
// TODO Validate this is the right set of protocols; settings.protocols was empty here.
225224
for (String protocol : settings.resolveServiceProtocols(service)) {
226-
String serdeFunctionName = getSerdeFunctionName(symbol, protocol, inputOrOutput);
225+
String serdeFunctionName = ProtocolGenerator.getSerdeFunctionName(symbol, protocol, isInput);
227226
writer.addImport(serdeFunctionName, serdeFunctionName,
228227
"./protocols/" + ProtocolGenerator.getSanitizedName(protocol));
229228
writer.write("case '$L':", protocol)
230-
.write(" return $L($L, context);", serdeFunctionName, inputOrOutput);
229+
.write(" return $L($L, context);", serdeFunctionName, isInput ? "input" : "output");
231230
}
232231

233232
writer.write("default:")
234233
.write(" throw new Error(\"Unknown protocol, \" + protocol + \". Expected one of: $L\");",
235234
settings.getProtocols());
236235
});
237236
}
238-
239-
private static String getSerdeFunctionName(Symbol commandSymbol, String protocol, String inputOrOutput) {
240-
String functionName = StringUtils.uncapitalize(commandSymbol.getName());
241-
functionName += ProtocolGenerator.getSanitizedName(protocol);
242-
243-
if (inputOrOutput.equals("input")) {
244-
functionName += "Serialize";
245-
} else {
246-
functionName += "Deserialize";
247-
}
248-
249-
return functionName;
250-
}
251237
}

0 commit comments

Comments
 (0)