26
26
import software .amazon .smithy .model .shapes .StructureShape ;
27
27
import software .amazon .smithy .typescript .codegen .integration .ProtocolGenerator ;
28
28
import software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin ;
29
- import software .amazon .smithy .utils .StringUtils ;
30
29
31
30
/**
32
31
* Generates a client command using plugins.
@@ -202,7 +201,7 @@ private void writeSerde() {
202
201
.write ("protocol: string," )
203
202
.write ("context: SerdeContext" )
204
203
.dedent ()
205
- .openBlock ("): $T {" , "}" , applicationProtocol .getRequestType (), () -> writeSerdeDispatcher ("input" ));
204
+ .openBlock ("): $T {" , "}" , applicationProtocol .getRequestType (), () -> writeSerdeDispatcher (true ));
206
205
207
206
writer .write ("" )
208
207
.write ("private deserialize(" )
@@ -211,41 +210,30 @@ private void writeSerde() {
211
210
.write ("protocol: string," )
212
211
.write ("context: SerdeContext" )
213
212
.dedent ()
214
- .openBlock ("): Promise<$L> {" , "}" , outputType , () -> writeSerdeDispatcher ("output" ))
213
+ .openBlock ("): Promise<$L> {" , "}" , outputType , () -> writeSerdeDispatcher (false ))
215
214
.write ("" );
216
215
}
217
216
218
- private void writeSerdeDispatcher (String inputOrOutput ) {
217
+ private void writeSerdeDispatcher (boolean isInput ) {
219
218
writer .openBlock ("switch (protocol) {" , "}" , () -> {
220
219
// Generate case statements for each supported protocol.
221
220
// For example:
222
221
// case 'aws.rest-json-1.1':
223
222
// return getFooCommandAws_RestJson1_1Serialize(input, utils);
224
223
// TODO Validate this is the right set of protocols; settings.protocols was empty here.
225
224
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 );
227
228
writer .addImport (serdeFunctionName , serdeFunctionName ,
228
229
"./protocols/" + ProtocolGenerator .getSanitizedName (protocol ));
229
230
writer .write ("case '$L':" , protocol )
230
- .write (" return $L($L, context);" , serdeFunctionName , inputOrOutput );
231
+ .write (" return $L($L, context);" , serdeFunctionName , isInput ? "input" : "output" );
231
232
}
232
233
233
234
writer .write ("default:" )
234
235
.write (" throw new Error(\" Unknown protocol, \" + protocol + \" . Expected one of: $L\" );" ,
235
236
settings .getProtocols ());
236
237
});
237
238
}
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
- }
251
239
}
0 commit comments