@@ -87,19 +87,17 @@ public void generateSharedComponents(GenerationContext context) {
8787 }
8888
8989 @ Override
90- protected void writeDefaultHeaders (GenerationContext context , OperationShape operation ) {
91- super .writeDefaultHeaders (context , operation );
90+ protected void writeDefaultInputHeaders (GenerationContext context , OperationShape operation ) {
9291 AwsProtocolUtils .generateUnsignedPayloadSigV4Header (context , operation );
9392 }
9493
9594 @ Override
9695 protected void writeDefaultErrorHeaders (GenerationContext context , StructureShape error ) {
97- super .writeDefaultErrorHeaders (context , error );
9896 context .getWriter ().write ("'x-amzn-errortype': $S," , error .getId ().getName ());
9997 }
10098
10199 @ Override
102- public void serializeInputDocument (
100+ protected void serializeInputDocumentBody (
103101 GenerationContext context ,
104102 OperationShape operation ,
105103 List <HttpBinding > documentBindings
@@ -110,7 +108,41 @@ public void serializeInputDocument(
110108 writer .write ("body = \" \" ;" );
111109 return ;
112110 }
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+ }
113143
144+ private void serializeDocumentBody (GenerationContext context , List <HttpBinding > documentBindings ) {
145+ TypeScriptWriter writer = context .getWriter ();
114146 SymbolProvider symbolProvider = context .getSymbolProvider ();
115147
116148 writer .openBlock ("body = JSON.stringify({" , "});" , () -> {
@@ -147,9 +179,34 @@ protected void serializeInputPayload(
147179 OperationShape operation ,
148180 HttpBinding payloadBinding
149181 ) {
150- // We want the standard serialization, but need to alter it to JSON.
151182 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+ }
152195
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+ ) {
153210 TypeScriptWriter writer = context .getWriter ();
154211 MemberShape payloadMember = payloadBinding .getMember ();
155212 Shape target = context .getModel ().expectShape (payloadMember .getTarget ());
@@ -172,6 +229,11 @@ private DocumentMemberSerVisitor getMemberSerVisitor(GenerationContext context,
172229 return new JsonMemberSerVisitor (context , dataSource , getDocumentTimestampFormat ());
173230 }
174231
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+
175237 @ Override
176238 protected void writeErrorCodeParser (GenerationContext context ) {
177239 TypeScriptWriter writer = context .getWriter ();
@@ -181,9 +243,34 @@ protected void writeErrorCodeParser(GenerationContext context) {
181243 }
182244
183245 @ 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 (
185273 GenerationContext context ,
186- Shape operationOrError ,
187274 List <HttpBinding > documentBindings
188275 ) {
189276 TypeScriptWriter writer = context .getWriter ();
@@ -205,20 +292,50 @@ public void deserializeOutputDocument(
205292 }
206293 }
207294
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 (
209329 GenerationContext context ,
210330 HttpBinding payloadBinding
211331 ) {
212- HttpBinding returnedBinding = super .readResponsePayload (context , payloadBinding );
213332 TypeScriptWriter writer = context .getWriter ();
214333 Shape target = context .getModel ().expectShape (payloadBinding .getMember ().getTarget ());
215334
216335 // Decode the body from a JSON string.
217336 if (target instanceof DocumentShape ) {
218337 writer .write ("contents.$L = JSON.parse(data);" , payloadBinding .getMemberName ());
219338 }
220-
221- return returnedBinding ;
222339 }
223340
224341 private DocumentMemberDeserVisitor getMemberDeserVisitor (GenerationContext context , String dataSource ) {
0 commit comments