@@ -218,7 +218,7 @@ private void generateOperationSerializer(
218
218
writeHeaders (context , operation , bindingIndex );
219
219
writeResolvedPath (context , operation , bindingIndex , trait );
220
220
boolean hasQueryComponents = writeRequestQueryString (context , operation , bindingIndex , trait );
221
- List <HttpBinding > documentBindings = writeRequestBody (context , operation , bindingIndex );
221
+ List <HttpBinding > bodyBindings = writeRequestBody (context , operation , bindingIndex );
222
222
boolean hasHostPrefix = operation .hasTrait (EndpointTrait .class );
223
223
224
224
if (hasHostPrefix ) {
@@ -237,14 +237,15 @@ private void generateOperationSerializer(
237
237
if (hasQueryComponents ) {
238
238
writer .write ("query: query," );
239
239
}
240
- if (!documentBindings .isEmpty ()) {
241
- // Track all shapes bound to the document so their serializers may be generated.
242
- documentBindings .stream ()
240
+ if (!bodyBindings .isEmpty ()) {
241
+ // Track all shapes bound to the body so their serializers may be generated.
242
+ bodyBindings .stream ()
243
243
.map (HttpBinding ::getMember )
244
244
.map (member -> context .getModel ().expectShape (member .getTarget ()))
245
245
.forEach (serializingDocumentShapes ::add );
246
- writer .write ("body: body," );
247
246
}
247
+ // Always set the body,
248
+ writer .write ("body: body," );
248
249
});
249
250
});
250
251
@@ -388,25 +389,29 @@ private List<HttpBinding> writeRequestBody(
388
389
HttpBindingIndex bindingIndex
389
390
) {
390
391
TypeScriptWriter writer = context .getWriter ();
391
- List <HttpBinding > documentBindings = bindingIndex .getRequestBindings (operation , Location .DOCUMENT );
392
- documentBindings .sort (Comparator .comparing (HttpBinding ::getMemberName ));
393
- List <HttpBinding > payloadBindings = bindingIndex .getRequestBindings (operation , Location .PAYLOAD );
392
+ // Write the default `body` property.
393
+ writer .write ("let body: any;" );
394
394
395
- if (!documentBindings .isEmpty ()) {
396
- // Write the default `body` property.
397
- writer .write ("let body: any;" );
398
- serializeInputDocument (context , operation , documentBindings );
399
- return documentBindings ;
400
- }
395
+ // Handle a payload binding explicitly.
396
+ List <HttpBinding > payloadBindings = bindingIndex .getRequestBindings (operation , Location .PAYLOAD );
401
397
if (!payloadBindings .isEmpty ()) {
402
- // Write the default `body` property.
403
- writer .write ("let body: any;" );
404
398
// There can only be one payload binding.
405
399
HttpBinding payloadBinding = payloadBindings .get (0 );
406
400
serializeInputPayload (context , operation , payloadBinding );
407
401
return payloadBindings ;
408
402
}
409
403
404
+ // If we have document bindings or need a defaulted request body,
405
+ // use the input document serialization.
406
+ List <HttpBinding > documentBindings = bindingIndex .getRequestBindings (operation , Location .DOCUMENT );
407
+ if (!documentBindings .isEmpty () || bindingIndex .getRequestBindings (operation ).isEmpty ()) {
408
+ documentBindings .sort (Comparator .comparing (HttpBinding ::getMemberName ));
409
+
410
+ serializeInputDocument (context , operation , documentBindings );
411
+ return documentBindings ;
412
+ }
413
+
414
+ // Otherwise, we have no bindings to add shapes from.
410
415
return ListUtils .of ();
411
416
}
412
417
@@ -606,6 +611,9 @@ protected void writeDefaultHeaders(GenerationContext context, OperationShape ope
606
611
* {@code body} variable that will be serialized as the request body.
607
612
* This variable will already be defined in scope.
608
613
*
614
+ * Implementations MUST properly fill the body parameter even if no
615
+ * document bindings are present.
616
+ *
609
617
* <p>For example:
610
618
*
611
619
* <pre>{@code
0 commit comments