@@ -1357,24 +1357,21 @@ protected abstract void serializeInputDocumentBody(
1357
1357
* The value set is expected to by a JavaScript ${@code Uint8Array} type and is to be encoded as the
1358
1358
* event payload.
1359
1359
*
1360
- * <p>Two parameters will be available in scope:
1360
+ * <p>Three parameters will be available in scope:
1361
1361
* <ul>
1362
+ * <li>{@code body}: The serialized event payload object to needs to be serialized</li>
1362
1363
* <li>{@code message: <T>}: The partially constructed event message.</li>
1363
1364
* <li>{@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.</li>
1364
1365
* </ul>
1365
1366
*
1366
1367
* <p>For example:
1367
1368
*
1368
1369
* <pre>{@code
1369
- * message.body = context.utf8Decoder(JSON.stringify(bodyParams ));
1370
+ * message.body = context.utf8Decoder(JSON.stringify(body ));
1370
1371
* }</pre>
1371
1372
* @param context The generation context.
1372
- * @param payloadShape The payload shape. Only structure and union shape is serialized as document.
1373
1373
*/
1374
- protected abstract void serializeInputEventDocumentPayload (
1375
- GenerationContext context ,
1376
- Shape payloadShape
1377
- );
1374
+ protected abstract void serializeInputEventDocumentPayload (GenerationContext context );
1378
1375
1379
1376
/**
1380
1377
* Writes the code needed to serialize a protocol output document.
@@ -1640,7 +1637,7 @@ private void writeEventBody(GenerationContext context, StructureShape event) {
1640
1637
.filter (member -> member .hasTrait (EventPayloadTrait .class ))
1641
1638
.collect (Collectors .toList ());
1642
1639
Shape payloadShape = payloadMembers .isEmpty ()
1643
- ? event
1640
+ ? event // implicit payload
1644
1641
: model .expectShape (payloadMembers .get (0 ).getTarget ());
1645
1642
if (payloadShape instanceof BlobShape || payloadShape instanceof StringShape ) {
1646
1643
// Since event itself must be a structure shape, so string or blob payload member must has eventPayload
@@ -1651,7 +1648,18 @@ private void writeEventBody(GenerationContext context, StructureShape event) {
1651
1648
getInputValue (context , Location .PAYLOAD , "input." + payloadMemberName , payloadMember ,
1652
1649
model .expectShape (payloadMember .getTarget ())));
1653
1650
} else if (payloadShape instanceof StructureShape || payloadShape instanceof UnionShape ) {
1654
- serializeInputEventDocumentPayload (context , payloadShape );
1651
+ // handle implicit event payload by removing members with eventHeader trait.
1652
+ List <MemberShape > headerMembers = event .getAllMembers ().values ().stream ()
1653
+ .filter (member -> member .hasTrait (EventHeaderTrait .class )).collect (Collectors .toList ());
1654
+ for (MemberShape headerMember : headerMembers ) {
1655
+ String memberName = headerMember .getMemberName ();
1656
+ writer .write ("delete input[$S]" , memberName );
1657
+ }
1658
+ SymbolProvider symbolProvider = context .getSymbolProvider ();
1659
+ Symbol symbol = symbolProvider .toSymbol (payloadShape );
1660
+ String serFunctionName = ProtocolGenerator .getSerFunctionName (symbol , context .getProtocolName ());
1661
+ writer .write ("const body = $L(input, context);" , serFunctionName );
1662
+ serializeInputEventDocumentPayload (context );
1655
1663
} else {
1656
1664
throw new CodegenException (String .format ("Unexpected shape type bound to event payload: `%s`" ,
1657
1665
payloadShape .getType ()));
0 commit comments