@@ -87,19 +87,17 @@ public void generateSharedComponents(GenerationContext context) {
87
87
}
88
88
89
89
@ Override
90
- protected void writeDefaultHeaders (GenerationContext context , OperationShape operation ) {
91
- super .writeDefaultHeaders (context , operation );
90
+ protected void writeDefaultInputHeaders (GenerationContext context , OperationShape operation ) {
92
91
AwsProtocolUtils .generateUnsignedPayloadSigV4Header (context , operation );
93
92
}
94
93
95
94
@ Override
96
95
protected void writeDefaultErrorHeaders (GenerationContext context , StructureShape error ) {
97
- super .writeDefaultErrorHeaders (context , error );
98
96
context .getWriter ().write ("'x-amzn-errortype': $S," , error .getId ().getName ());
99
97
}
100
98
101
99
@ Override
102
- public void serializeInputDocument (
100
+ protected void serializeInputDocumentBody (
103
101
GenerationContext context ,
104
102
OperationShape operation ,
105
103
List <HttpBinding > documentBindings
@@ -110,7 +108,41 @@ public void serializeInputDocument(
110
108
writer .write ("body = \" \" ;" );
111
109
return ;
112
110
}
111
+ serializeDocumentBody (context , documentBindings );
112
+ }
113
+
114
+ @ Override
115
+ protected void serializeOutputDocumentBody (
116
+ GenerationContext context ,
117
+ OperationShape operation ,
118
+ List <HttpBinding > documentBindings
119
+ ) {
120
+ // Short circuit when we have no bindings.
121
+ TypeScriptWriter writer = context .getWriter ();
122
+ if (documentBindings .isEmpty ()) {
123
+ writer .write ("body = \" {}\" ;" );
124
+ return ;
125
+ }
126
+ serializeDocumentBody (context , documentBindings );
127
+ }
128
+
129
+ @ Override
130
+ protected void serializeErrorDocumentBody (
131
+ GenerationContext context ,
132
+ StructureShape error ,
133
+ List <HttpBinding > documentBindings
134
+ ) {
135
+ // Short circuit when we have no bindings.
136
+ TypeScriptWriter writer = context .getWriter ();
137
+ if (documentBindings .isEmpty ()) {
138
+ writer .write ("body = \" {}\" ;" );
139
+ return ;
140
+ }
141
+ serializeDocumentBody (context , documentBindings );
142
+ }
113
143
144
+ private void serializeDocumentBody (GenerationContext context , List <HttpBinding > documentBindings ) {
145
+ TypeScriptWriter writer = context .getWriter ();
114
146
SymbolProvider symbolProvider = context .getSymbolProvider ();
115
147
116
148
writer .openBlock ("body = JSON.stringify({" , "});" , () -> {
@@ -147,9 +179,34 @@ protected void serializeInputPayload(
147
179
OperationShape operation ,
148
180
HttpBinding payloadBinding
149
181
) {
150
- // We want the standard serialization, but need to alter it to JSON.
151
182
super .serializeInputPayload (context , operation , payloadBinding );
183
+ serializePayload (context , payloadBinding );
184
+ }
185
+
186
+ @ Override
187
+ protected void serializeOutputPayload (
188
+ GenerationContext context ,
189
+ OperationShape operation ,
190
+ HttpBinding payloadBinding
191
+ ) {
192
+ super .serializeOutputPayload (context , operation , payloadBinding );
193
+ serializePayload (context , payloadBinding );
194
+ }
152
195
196
+ @ Override
197
+ protected void serializeErrorPayload (
198
+ GenerationContext context ,
199
+ StructureShape error ,
200
+ HttpBinding payloadBinding
201
+ ) {
202
+ super .serializeErrorPayload (context , error , payloadBinding );
203
+ serializePayload (context , payloadBinding );
204
+ }
205
+
206
+ private void serializePayload (
207
+ GenerationContext context ,
208
+ HttpBinding payloadBinding
209
+ ) {
153
210
TypeScriptWriter writer = context .getWriter ();
154
211
MemberShape payloadMember = payloadBinding .getMember ();
155
212
Shape target = context .getModel ().expectShape (payloadMember .getTarget ());
@@ -172,6 +229,11 @@ private DocumentMemberSerVisitor getMemberSerVisitor(GenerationContext context,
172
229
return new JsonMemberSerVisitor (context , dataSource , getDocumentTimestampFormat ());
173
230
}
174
231
232
+ protected boolean shouldWriteDefaultOutputBody (GenerationContext context , OperationShape operation ) {
233
+ // Operations that have any defined output shape should always send a default body.
234
+ return operation .getOutput ().isPresent ();
235
+ }
236
+
175
237
@ Override
176
238
protected void writeErrorCodeParser (GenerationContext context ) {
177
239
TypeScriptWriter writer = context .getWriter ();
@@ -181,9 +243,34 @@ protected void writeErrorCodeParser(GenerationContext context) {
181
243
}
182
244
183
245
@ Override
184
- public void deserializeOutputDocument (
246
+ protected void deserializeInputDocumentBody (
247
+ GenerationContext context ,
248
+ OperationShape operation ,
249
+ List <HttpBinding > documentBindings
250
+ ) {
251
+ deserializeDocumentBody (context , documentBindings );
252
+ }
253
+
254
+ @ Override
255
+ protected void deserializeOutputDocumentBody (
256
+ GenerationContext context ,
257
+ OperationShape operation ,
258
+ List <HttpBinding > documentBindings
259
+ ) {
260
+ deserializeDocumentBody (context , documentBindings );
261
+ }
262
+
263
+ @ Override
264
+ protected void deserializeErrorDocumentBody (
265
+ GenerationContext context ,
266
+ StructureShape error ,
267
+ List <HttpBinding > documentBindings
268
+ ) {
269
+ deserializeDocumentBody (context , documentBindings );
270
+ }
271
+
272
+ private void deserializeDocumentBody (
185
273
GenerationContext context ,
186
- Shape operationOrError ,
187
274
List <HttpBinding > documentBindings
188
275
) {
189
276
TypeScriptWriter writer = context .getWriter ();
@@ -205,20 +292,50 @@ public void deserializeOutputDocument(
205
292
}
206
293
}
207
294
208
- protected HttpBinding readResponsePayload (
295
+ @ Override
296
+ protected HttpBinding deserializeInputPayload (
297
+ GenerationContext context ,
298
+ OperationShape operation ,
299
+ HttpBinding payloadBinding
300
+ ) {
301
+ HttpBinding returnedBinding = super .deserializeInputPayload (context , operation , payloadBinding );
302
+ readPayload (context , payloadBinding );
303
+ return returnedBinding ;
304
+ }
305
+
306
+ @ Override
307
+ protected HttpBinding deserializeOutputPayload (
308
+ GenerationContext context ,
309
+ OperationShape operation ,
310
+ HttpBinding payloadBinding
311
+ ) {
312
+ HttpBinding returnedBinding = super .deserializeOutputPayload (context , operation , payloadBinding );
313
+ readPayload (context , payloadBinding );
314
+ return returnedBinding ;
315
+ }
316
+
317
+ @ Override
318
+ protected HttpBinding deserializeErrorPayload (
319
+ GenerationContext context ,
320
+ StructureShape error ,
321
+ HttpBinding payloadBinding
322
+ ) {
323
+ HttpBinding returnedBinding = super .deserializeErrorPayload (context , error , payloadBinding );
324
+ readPayload (context , payloadBinding );
325
+ return returnedBinding ;
326
+ }
327
+
328
+ protected void readPayload (
209
329
GenerationContext context ,
210
330
HttpBinding payloadBinding
211
331
) {
212
- HttpBinding returnedBinding = super .readResponsePayload (context , payloadBinding );
213
332
TypeScriptWriter writer = context .getWriter ();
214
333
Shape target = context .getModel ().expectShape (payloadBinding .getMember ().getTarget ());
215
334
216
335
// Decode the body from a JSON string.
217
336
if (target instanceof DocumentShape ) {
218
337
writer .write ("contents.$L = JSON.parse(data);" , payloadBinding .getMemberName ());
219
338
}
220
-
221
- return returnedBinding ;
222
339
}
223
340
224
341
private DocumentMemberDeserVisitor getMemberDeserVisitor (GenerationContext context , String dataSource ) {
0 commit comments