@@ -87,36 +87,62 @@ public void generateSharedComponents(GenerationContext context) {
87
87
}
88
88
89
89
@ Override
90
- protected void writeDefaultHeaders (GenerationContext context , Shape operationOrError , boolean isInput ) {
91
- super .writeDefaultHeaders (context , operationOrError , isInput );
92
- if (operationOrError .isOperationShape ()) {
93
- OperationShape operation = operationOrError .asOperationShape ().get ();
94
- if (isInput ) {
95
- AwsProtocolUtils .generateUnsignedPayloadSigV4Header (context , operation );
96
- }
97
- } else if (operationOrError .isStructureShape ()) {
98
- context .getWriter ().write ("'x-amzn-errortype': $S," , operationOrError .getId ().getName ());
90
+ protected void writeDefaultInputHeaders (GenerationContext context , OperationShape operation ) {
91
+ AwsProtocolUtils .generateUnsignedPayloadSigV4Header (context , operation );
92
+ }
93
+
94
+ @ Override
95
+ protected void writeDefaultErrorHeaders (GenerationContext context , StructureShape error ) {
96
+ context .getWriter ().write ("'x-amzn-errortype': $S," , error .getId ().getName ());
97
+ }
98
+
99
+ @ Override
100
+ public void serializeInputDocumentBody (
101
+ GenerationContext context ,
102
+ OperationShape operation ,
103
+ List <HttpBinding > documentBindings
104
+ ) {
105
+ // Short circuit when we have no bindings.
106
+ TypeScriptWriter writer = context .getWriter ();
107
+ if (documentBindings .isEmpty ()) {
108
+ writer .write ("body = \" \" ;" );
109
+ return ;
99
110
}
111
+ serializeDocumentBody (context , documentBindings );
100
112
}
101
113
102
114
@ Override
103
- public void serializeDocumentBody (
115
+ public void serializeOutputDocumentBody (
104
116
GenerationContext context ,
105
117
OperationShape operation ,
106
- List <HttpBinding > documentBindings ,
107
- boolean isInput
118
+ List <HttpBinding > documentBindings
108
119
) {
109
120
// Short circuit when we have no bindings.
110
121
TypeScriptWriter writer = context .getWriter ();
111
122
if (documentBindings .isEmpty ()) {
112
- if (isInput ) {
113
- writer .write ("body = \" \" ;" );
114
- } else {
115
- writer .write ("body = \" {}\" ;" );
116
- }
123
+ writer .write ("body = \" {}\" ;" );
117
124
return ;
118
125
}
126
+ serializeDocumentBody (context , documentBindings );
127
+ }
119
128
129
+ @ Override
130
+ public 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
+ }
143
+
144
+ private void serializeDocumentBody (GenerationContext context , List <HttpBinding > documentBindings ) {
145
+ TypeScriptWriter writer = context .getWriter ();
120
146
SymbolProvider symbolProvider = context .getSymbolProvider ();
121
147
122
148
writer .openBlock ("body = JSON.stringify({" , "});" , () -> {
@@ -148,15 +174,39 @@ public void serializeDocumentBody(
148
174
}
149
175
150
176
@ Override
151
- protected void serializePayload (
177
+ protected void serializeInputPayload (
178
+ GenerationContext context ,
179
+ OperationShape operation ,
180
+ HttpBinding payloadBinding
181
+ ) {
182
+ super .serializeInputPayload (context , operation , payloadBinding );
183
+ serializePayload (context , payloadBinding );
184
+ }
185
+
186
+ @ Override
187
+ protected void serializeOutputPayload (
152
188
GenerationContext context ,
153
189
OperationShape operation ,
154
- HttpBinding payloadBinding ,
155
- boolean isInput
190
+ HttpBinding payloadBinding
156
191
) {
157
- // We want the standard serialization, but need to alter it to JSON.
158
- super .serializePayload (context , operation , payloadBinding , isInput );
192
+ super .serializeOutputPayload (context , operation , payloadBinding );
193
+ serializePayload (context , payloadBinding );
194
+ }
159
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
+ ) {
160
210
TypeScriptWriter writer = context .getWriter ();
161
211
MemberShape payloadMember = payloadBinding .getMember ();
162
212
Shape target = context .getModel ().expectShape (payloadMember .getTarget ());
@@ -179,17 +229,9 @@ private DocumentMemberSerVisitor getMemberSerVisitor(GenerationContext context,
179
229
return new JsonMemberSerVisitor (context , dataSource , getDocumentTimestampFormat ());
180
230
}
181
231
182
- @ Override
183
- protected boolean shouldWriteDefaultBody (GenerationContext context , Shape operationOrError , boolean isInput ) {
184
- if (!isInput ) {
185
- // Operations that have any defined output shape should always send a default body.
186
- if (operationOrError .isOperationShape ()) {
187
- OperationShape operation = operationOrError .asOperationShape ().get ();
188
- return operation .getOutput ().isPresent ();
189
- }
190
- return true ;
191
- }
192
- return super .shouldWriteDefaultBody (context , operationOrError , isInput );
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 ();
193
235
}
194
236
195
237
@ Override
@@ -201,11 +243,35 @@ protected void writeErrorCodeParser(GenerationContext context) {
201
243
}
202
244
203
245
@ Override
204
- public void deserializeDocumentBody (
246
+ public void deserializeInputDocumentBody (
247
+ GenerationContext context ,
248
+ OperationShape operation ,
249
+ List <HttpBinding > documentBindings
250
+ ) {
251
+ deserializeDocumentBody (context , documentBindings );
252
+ }
253
+
254
+ @ Override
255
+ public void deserializeOutputDocumentBody (
256
+ GenerationContext context ,
257
+ OperationShape operation ,
258
+ List <HttpBinding > documentBindings
259
+ ) {
260
+ deserializeDocumentBody (context , documentBindings );
261
+ }
262
+
263
+ @ Override
264
+ public void deserializeErrorDocumentBody (
205
265
GenerationContext context ,
206
- Shape operationOrError ,
207
- List <HttpBinding > documentBindings ,
208
- boolean isInput
266
+ StructureShape error ,
267
+ List <HttpBinding > documentBindings
268
+ ) {
269
+ deserializeDocumentBody (context , documentBindings );
270
+ }
271
+
272
+ private void deserializeDocumentBody (
273
+ GenerationContext context ,
274
+ List <HttpBinding > documentBindings
209
275
) {
210
276
TypeScriptWriter writer = context .getWriter ();
211
277
SymbolProvider symbolProvider = context .getSymbolProvider ();
@@ -226,20 +292,50 @@ public void deserializeDocumentBody(
226
292
}
227
293
}
228
294
229
- 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 (
230
329
GenerationContext context ,
231
330
HttpBinding payloadBinding
232
331
) {
233
- HttpBinding returnedBinding = super .readResponsePayload (context , payloadBinding );
234
332
TypeScriptWriter writer = context .getWriter ();
235
333
Shape target = context .getModel ().expectShape (payloadBinding .getMember ().getTarget ());
236
334
237
335
// Decode the body from a JSON string.
238
336
if (target instanceof DocumentShape ) {
239
337
writer .write ("contents.$L = JSON.parse(data);" , payloadBinding .getMemberName ());
240
338
}
241
-
242
- return returnedBinding ;
243
339
}
244
340
245
341
private DocumentMemberDeserVisitor getMemberDeserVisitor (GenerationContext context , String dataSource ) {
0 commit comments