Skip to content

Commit 7748297

Browse files
author
Steven Yuan
authored
Add eventStream smithy context (#1111)
1 parent 3864faa commit 7748297

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
import software.amazon.smithy.model.shapes.OperationShape;
2828
import software.amazon.smithy.model.shapes.ServiceShape;
2929
import software.amazon.smithy.typescript.codegen.LanguageTarget;
30+
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenContext;
3031
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
3132
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
3233
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
34+
import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection;
35+
import software.amazon.smithy.utils.CodeInterceptor;
36+
import software.amazon.smithy.utils.CodeSection;
3337
import software.amazon.smithy.utils.ListUtils;
3438
import software.amazon.smithy.utils.MapUtils;
3539
import software.amazon.smithy.utils.SmithyInternalApi;
@@ -99,6 +103,31 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
99103
}
100104
}
101105

106+
@Override
107+
public List<? extends CodeInterceptor<? extends CodeSection, TypeScriptWriter>> interceptors(
108+
TypeScriptCodegenContext codegenContext
109+
) {
110+
return List.of(CodeInterceptor.appender(SmithyContextCodeSection.class, (w, s) -> {
111+
EventStreamIndex eventStreamIndex = EventStreamIndex.of(s.getModel());
112+
boolean input = eventStreamIndex.getInputInfo(s.getOperation()).isPresent();
113+
boolean output = eventStreamIndex.getOutputInfo(s.getOperation()).isPresent();
114+
// If not event streaming for I/O, don't write anything
115+
if (!input && !output) {
116+
return;
117+
}
118+
// Otherwise, write present input and output streaming
119+
w.writeDocs("@internal");
120+
w.openBlock("eventStream: {", "},", () -> {
121+
if (input) {
122+
w.write("input: true,");
123+
}
124+
if (output) {
125+
w.write("output: true,");
126+
}
127+
});
128+
}));
129+
}
130+
102131
private static boolean hasEventStream(
103132
Model model,
104133
ServiceShape service

0 commit comments

Comments
 (0)