@@ -89,14 +89,14 @@ public void run() {
89
89
writer .addImport ("ServiceInputTypes" , "ServiceInputTypes" , serviceSymbol .getNamespace ());
90
90
writer .addImport ("ServiceOutputTypes" , "ServiceOutputTypes" , serviceSymbol .getNamespace ());
91
91
writer .addImport ("Command" , "$Command" , "@aws-sdk/smithy-client" );
92
- writer .addImport ("*" , "$types" , "@aws-sdk/types" );
92
+ writer .addImport ("FinalizeHandlerArguments" , "FinalizeHandlerArguments" , "@aws-sdk/types" );
93
+ writer .addImport ("Handler" , "Handler" , "@aws-sdk/types" );
94
+ writer .addImport ("HandlerExecutionContext" , "HandlerExecutionContext" , "@aws-sdk/types" );
95
+ writer .addImport ("MiddlewareStack" , "MiddlewareStack" , "@aws-sdk/types" );
96
+ writer .addImport ("SerdeContext" , "SerdeContext" , "@aws-sdk/types" );
93
97
94
98
addInputAndOutputTypes ();
95
99
96
- // This "Utils" type is used when serializing and deserializing commands. It
97
- // provides various platform specific methods that serde needs.
98
- writer .write ("type Utils = { [key: string]: any };" ).write ("" );
99
-
100
100
String name = symbol .getName ();
101
101
writer .openBlock ("export class $L extends $$Command<$L, $L> {" , "}" , name , inputType , outputType , () -> {
102
102
@@ -126,17 +126,13 @@ private void generateCommandConstructor() {
126
126
.pushState (COMMAND_CONSTRUCTOR_SECTION )
127
127
.write ("super();" )
128
128
.popState ()
129
- .write ("// Start section: $L" , COMMAND_CONSTRUCTOR_SECTION );
129
+ .write ("// End section: $L" , COMMAND_CONSTRUCTOR_SECTION );
130
130
});
131
131
}
132
132
133
133
private void generateCommandMiddlewareResolver (String configType ) {
134
- Symbol ser = Symbol .builder ()
135
- .name ("serializerPlugin" )
136
- .namespace ("@aws-sdk/middleware-serde" , "/" )
137
- .build ();
138
- Symbol deser = Symbol .builder ()
139
- .name ("deserializerPlugin" )
134
+ Symbol serde = Symbol .builder ()
135
+ .name ("serdePlugin" )
140
136
.namespace ("@aws-sdk/middleware-serde" , "/" )
141
137
.addDependency (PackageJsonGenerator .NORMAL_DEPENDENCY ,
142
138
"@aws-sdk/middleware-serde" ,
@@ -145,26 +141,25 @@ private void generateCommandMiddlewareResolver(String configType) {
145
141
146
142
writer .write ("resolveMiddleware(" )
147
143
.indent ()
148
- .write ("clientStack: $$types. MiddlewareStack<$L, $L>," , inputType , outputType )
144
+ .write ("clientStack: MiddlewareStack<$L, $L>," , inputType , outputType )
149
145
.write ("configuration: $L," , configType )
150
146
.write ("options?: $T" , applicationProtocol .getOptionsType ())
151
147
.dedent ();
152
- writer .openBlock ("): $$types.Handler<$L, $L> {" , "}" , inputType , outputType , () -> {
153
- // Add serialization and deserialization plugins.
154
- writer .write ("this.use($T(configuration, this.serialize));" , ser );
155
- writer .write ("this.use($T<$L>(configuration, this.deserialize));" , deser , outputType );
148
+ writer .openBlock ("): Handler<$L, $L> {" , "}" , inputType , outputType , () -> {
149
+ // Add serialization and deserialization plugin.
150
+ writer .write ("this.use($T(configuration, this.serialize, this.deserialize));" , serde );
156
151
157
152
// Add customizations.
158
153
addCommandSpecificPlugins ();
159
154
160
155
// Resolve the middleware stack.
161
156
writer .write ("\n const stack = clientStack.concat(this.middlewareStack);\n " );
162
- writer .openBlock ("const handlerExecutionContext: $$types. HandlerExecutionContext = {" , "}" , () -> {
157
+ writer .openBlock ("const handlerExecutionContext: HandlerExecutionContext = {" , "}" , () -> {
163
158
writer .write ("logger: {} as any," );
164
159
});
165
160
writer .write ("const { httpHandler } = configuration;" );
166
161
writer .openBlock ("return stack.resolve(" , ");" , () -> {
167
- writer .write ("(request: $$types. FinalizeHandlerArguments<any>) => " );
162
+ writer .write ("(request: FinalizeHandlerArguments<any>) => " );
168
163
writer .write (" httpHandler.handle(request.request as $T, options || {})," ,
169
164
applicationProtocol .getRequestType ());
170
165
writer .write ("handlerExecutionContext" );
@@ -205,7 +200,7 @@ private void writeSerde() {
205
200
.indent ()
206
201
.write ("input: $L," , inputType )
207
202
.write ("protocol: string," )
208
- .write ("utils?: Utils " )
203
+ .write ("context: SerdeContext " )
209
204
.dedent ()
210
205
.openBlock ("): $T {" , "}" , applicationProtocol .getRequestType (), () -> writeSerdeDispatcher ("input" ));
211
206
@@ -214,7 +209,7 @@ private void writeSerde() {
214
209
.indent ()
215
210
.write ("output: $T," , applicationProtocol .getResponseType ())
216
211
.write ("protocol: string," )
217
- .write ("utils?: Utils " )
212
+ .write ("context: SerdeContext " )
218
213
.dedent ()
219
214
.openBlock ("): Promise<$L> {" , "}" , outputType , () -> writeSerdeDispatcher ("output" ))
220
215
.write ("" );
@@ -226,11 +221,13 @@ private void writeSerdeDispatcher(String inputOrOutput) {
226
221
// For example:
227
222
// case 'aws.rest-json-1.1':
228
223
// return getFooCommandAws_RestJson1_1Serialize(input, utils);
229
- //
230
- for (String protocol : settings .getProtocols ( )) {
224
+ // TODO Validate this is the right set of protocols; settings.protocols was empty here.
225
+ for (String protocol : settings .resolveServiceProtocols ( service )) {
231
226
String serdeFunctionName = getSerdeFunctionName (symbol , protocol , inputOrOutput );
227
+ writer .addImport (serdeFunctionName , serdeFunctionName ,
228
+ "./protocols/" + ProtocolGenerator .getSanitizedName (protocol ));
232
229
writer .write ("case '$L':" , protocol )
233
- .write (" return $L($L, utils );" , serdeFunctionName , inputOrOutput );
230
+ .write (" return $L($L, context );" , serdeFunctionName , inputOrOutput );
234
231
}
235
232
236
233
writer .write ("default:" )
0 commit comments