Skip to content

Commit be3972a

Browse files
committed
formatting
1 parent ebbe397 commit be3972a

File tree

7 files changed

+439
-440
lines changed

7 files changed

+439
-440
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/EventStreamGenerator.java

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ public static UnionShape getEventStreamOutputShape(GenerationContext context, Op
9090
* Shapes that referred by event will be added.
9191
*/
9292
public void generateEventStreamSerializers(
93-
GenerationContext context,
94-
ServiceShape service,
95-
String documentContentType,
96-
Runnable serializeInputEventDocumentPayload,
93+
GenerationContext context,
94+
ServiceShape service,
95+
String documentContentType,
96+
Runnable serializeInputEventDocumentPayload,
9797
Set<Shape> documentShapesToSerialize
9898
) {
9999
Model model = context.getModel();
@@ -118,11 +118,11 @@ public void generateEventStreamSerializers(
118118
});
119119
eventShapesToMarshall.forEach(event -> {
120120
generateEventMarshaller(
121-
context,
122-
event,
123-
documentContentType,
124-
serializeInputEventDocumentPayload,
125-
documentShapesToSerialize);
121+
context,
122+
event,
123+
documentContentType,
124+
serializeInputEventDocumentPayload,
125+
documentShapesToSerialize);
126126
});
127127
}
128128

@@ -190,14 +190,14 @@ private void generateEventStreamSerializer(GenerationContext context, UnionShape
190190
+ " context: $L\n"
191191
+ "): any => {", "}", methodName, getEventStreamSerdeContextType(context, eventsUnion), () -> {
192192
writer.openBlock("const eventMarshallingVisitor = (event: any): __Message => $T.visit(event, {", "});",
193-
eventsUnionSymbol, () -> {
194-
eventsUnion.getAllMembers().forEach((memberName, memberShape) -> {
195-
StructureShape target = model.expectShape(memberShape.getTarget(), StructureShape.class);
196-
String eventSerMethodName = getEventSerFunctionName(context, target);
197-
writer.write("$L: value => $L(value, context),", memberName, eventSerMethodName);
198-
});
199-
writer.write("_: value => value as any");
200-
});
193+
eventsUnionSymbol, () -> {
194+
eventsUnion.getAllMembers().forEach((memberName, memberShape) -> {
195+
StructureShape target = model.expectShape(memberShape.getTarget(), StructureShape.class);
196+
String eventSerMethodName = getEventSerFunctionName(context, target);
197+
writer.write("$L: value => $L(value, context),", memberName, eventSerMethodName);
198+
});
199+
writer.write("_: value => value as any");
200+
});
201201
writer.write("return context.eventStreamMarshaller.serialize(input, eventMarshallingVisitor);");
202202
});
203203
}
@@ -229,10 +229,10 @@ private Symbol getSymbol(GenerationContext context, Shape shape) {
229229
}
230230

231231
public void generateEventMarshaller(
232-
GenerationContext context,
233-
StructureShape event,
234-
String documentContentType,
235-
Runnable serializeInputEventDocumentPayload,
232+
GenerationContext context,
233+
StructureShape event,
234+
String documentContentType,
235+
Runnable serializeInputEventDocumentPayload,
236236
Set<Shape> documentShapesToSerialize
237237
) {
238238
String methodName = getEventSerFunctionName(context, event);
@@ -243,17 +243,17 @@ public void generateEventMarshaller(
243243
+ " input: $T,\n"
244244
+ " context: __SerdeContext\n"
245245
+ "): __Message => {", "}", methodName, symbol, () -> {
246-
writer.openBlock("const headers: __MessageHeaders = {", "}", () -> {
247-
//fix headers required by event stream
248-
writer.write("\":event-type\": { type: \"string\", value: $S },", symbol.getName());
249-
writer.write("\":message-type\": { type: \"string\", value: \"event\" },");
250-
writeEventContentTypeHeader(context, event, documentContentType);
251-
});
252-
writeEventHeaders(context, event);
253-
writeEventBody(context, event, serializeInputEventDocumentPayload,
254-
documentShapesToSerialize);
255-
writer.openBlock("return { headers, body };");
256-
});
246+
writer.openBlock("const headers: __MessageHeaders = {", "}", () -> {
247+
//fix headers required by event stream
248+
writer.write("\":event-type\": { type: \"string\", value: $S },", symbol.getName());
249+
writer.write("\":message-type\": { type: \"string\", value: \"event\" },");
250+
writeEventContentTypeHeader(context, event, documentContentType);
251+
});
252+
writeEventHeaders(context, event);
253+
writeEventBody(context, event, serializeInputEventDocumentPayload,
254+
documentShapesToSerialize);
255+
writer.openBlock("return { headers, body };");
256+
});
257257
}
258258

259259
private void writeEventContentTypeHeader(
@@ -283,8 +283,8 @@ private Optional<MemberShape> getEventPayloadMember(StructureShape event) {
283283
.filter(member -> member.hasTrait(EventPayloadTrait.class))
284284
.collect(Collectors.toList());
285285
return payloadMembers.isEmpty()
286-
? Optional.empty() // implicit payload
287-
: Optional.of(payloadMembers.get(0));
286+
? Optional.empty() // implicit payload
287+
: Optional.of(payloadMembers.get(0));
288288
}
289289

290290
private void writeEventHeaders(GenerationContext context, StructureShape event) {
@@ -327,8 +327,8 @@ private String getEventHeaderType(Shape shape) {
327327
*/
328328
private MemberShape getExplicitEventPayloadMember(StructureShape event) {
329329
return event.getAllMembers().values().stream()
330-
.filter(member -> member.hasTrait(EventPayloadTrait.class))
331-
.collect(Collectors.toList()).get(0);
330+
.filter(member -> member.hasTrait(EventPayloadTrait.class))
331+
.collect(Collectors.toList()).get(0);
332332
}
333333

334334
private void writeEventBody(
@@ -356,7 +356,7 @@ private void writeEventBody(
356356
serializeInputEventDocumentPayload.run();
357357
} else {
358358
throw new CodegenException(String.format("Unexpected shape type bound to event payload: `%s`",
359-
payloadShape.getType()));
359+
payloadShape.getType()));
360360
}
361361
});
362362
} else {
@@ -388,22 +388,22 @@ private void generateEventStreamDeserializer(GenerationContext context, UnionSha
388388
+ " output: any,\n"
389389
+ " context: $L\n"
390390
+ "): AsyncIterable<$T> => {", "}", methodName, contextType, eventsUnionSymbol, () -> {
391-
writer.openBlock("return context.eventStreamMarshaller.deserialize(", ");", () -> {
392-
writer.write("output,");
393-
writer.openBlock("async event => {", "}", () -> {
394-
eventsUnion.getAllMembers().forEach((name, member) -> {
395-
StructureShape event = model.expectShape(member.getTarget(), StructureShape.class);
396-
writer.openBlock("if (event[$S] != null) {", "}", name, () -> {
397-
writer.openBlock("return {", "};", () -> {
398-
String eventDeserMethodName = getEventDeserFunctionName(context, event);
399-
writer.write("$1L: await $2L(event[$1S], context),", name, eventDeserMethodName);
400-
});
401-
});
391+
writer.openBlock("return context.eventStreamMarshaller.deserialize(", ");", () -> {
392+
writer.write("output,");
393+
writer.openBlock("async event => {", "}", () -> {
394+
eventsUnion.getAllMembers().forEach((name, member) -> {
395+
StructureShape event = model.expectShape(member.getTarget(), StructureShape.class);
396+
writer.openBlock("if (event[$S] != null) {", "}", name, () -> {
397+
writer.openBlock("return {", "};", () -> {
398+
String eventDeserMethodName = getEventDeserFunctionName(context, event);
399+
writer.write("$1L: await $2L(event[$1S], context),", name, eventDeserMethodName);
402400
});
403-
writer.write("return {$$unknown: output};");
404401
});
405402
});
403+
writer.write("return {$$unknown: output};");
406404
});
405+
});
406+
});
407407
}
408408

409409
private String getDeserFunctionName(GenerationContext context, Shape shape) {
@@ -429,15 +429,15 @@ public void generateEventUnmarshaller(
429429
+ " output: any,\n"
430430
+ " context: __SerdeContext\n"
431431
+ "): Promise<$T> => {", "}", methodName, symbol, () -> {
432-
if (event.hasTrait(ErrorTrait.class)) {
433-
generateErrorEventUnmarshaller(context, event, errorShapesToDeserialize, isErrorCodeInBody);
434-
} else {
435-
writer.write("const contents: $L = {} as any;", symbol.getName());
436-
readEventHeaders(context, event);
437-
readEventBody(context, event, eventShapesToDeserialize);
438-
writer.write("return contents;");
439-
}
440-
});
432+
if (event.hasTrait(ErrorTrait.class)) {
433+
generateErrorEventUnmarshaller(context, event, errorShapesToDeserialize, isErrorCodeInBody);
434+
} else {
435+
writer.write("const contents: $L = {} as any;", symbol.getName());
436+
readEventHeaders(context, event);
437+
readEventBody(context, event, eventShapesToDeserialize);
438+
writer.write("return contents;");
439+
}
440+
});
441441
}
442442

443443
// Writes function content that unmarshall error event with error deserializer

0 commit comments

Comments
 (0)