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