Skip to content

Add eventStream smithy context #1111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenContext;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection;
import software.amazon.smithy.utils.CodeInterceptor;
import software.amazon.smithy.utils.CodeSection;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.MapUtils;
import software.amazon.smithy.utils.SmithyInternalApi;
Expand Down Expand Up @@ -99,6 +103,31 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
}
}

@Override
public List<? extends CodeInterceptor<? extends CodeSection, TypeScriptWriter>> interceptors(
TypeScriptCodegenContext codegenContext
) {
return List.of(CodeInterceptor.appender(SmithyContextCodeSection.class, (w, s) -> {
EventStreamIndex eventStreamIndex = EventStreamIndex.of(s.getModel());
boolean input = eventStreamIndex.getInputInfo(s.getOperation()).isPresent();
boolean output = eventStreamIndex.getOutputInfo(s.getOperation()).isPresent();
// If not event streaming for I/O, don't write anything
if (!input && !output) {
return;
}
// Otherwise, write present input and output streaming
w.writeDocs("@internal");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the internal annotation has no meaning here since this is not an accessible field

w.openBlock("eventStream: {", "},", () -> {
if (input) {
w.write("input: true,");
}
if (output) {
w.write("output: true,");
}
});
}));
}

private static boolean hasEventStream(
Model model,
ServiceShape service
Expand Down