Skip to content

Commit 3f14659

Browse files
authored
Merge pull request #13 from awslabs/serializer_updates
Improve complex serialization support
2 parents 1b4ff49 + f39ab60 commit 3f14659

File tree

3 files changed

+317
-64
lines changed

3 files changed

+317
-64
lines changed

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

Lines changed: 7 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,30 @@ 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 = isInput
226+
? ProtocolGenerator.getSerFunctionName(symbol, protocol)
227+
: ProtocolGenerator.getDeserFunctionName(symbol, protocol);
227228
writer.addImport(serdeFunctionName, serdeFunctionName,
228229
"./protocols/" + ProtocolGenerator.getSanitizedName(protocol));
229230
writer.write("case '$L':", protocol)
230-
.write(" return $L($L, context);", serdeFunctionName, inputOrOutput);
231+
.write(" return $L($L, context);", serdeFunctionName, isInput ? "input" : "output");
231232
}
232233

233234
writer.write("default:")
234235
.write(" throw new Error(\"Unknown protocol, \" + protocol + \". Expected one of: $L\");",
235236
settings.getProtocols());
236237
});
237238
}
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-
}
251239
}

0 commit comments

Comments
 (0)