From 7bf2e59e7d0c785f3225828d064b4e70d6592744 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:28:33 -0700 Subject: [PATCH] chore(codegen): make hasEventStreamInput utilities public (#6351) --- .../codegen/AddEventStreamHandlingDependency.java | 9 ++++----- .../codegen/AddTranscribeStreamingDependency.java | 10 ++-------- .../aws/typescript/codegen/AddWebsocketPlugin.java | 9 ++------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddEventStreamHandlingDependency.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddEventStreamHandlingDependency.java index de1936320c9b..42c463ba8b47 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddEventStreamHandlingDependency.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddEventStreamHandlingDependency.java @@ -63,7 +63,7 @@ public List getClientPlugins() { RuntimeClientPlugin.builder() .withConventions(AwsDependency.MIDDLEWARE_EVENTSTREAM.dependency, "EventStream", HAS_MIDDLEWARE) - .operationPredicate(AddEventStreamHandlingDependency::hasEventStreamInput) + .operationPredicate((m, s, o) -> hasEventStreamInput(m, o)) .build() ); } @@ -138,7 +138,7 @@ public Map> getRuntimeConfigWriters( } } - private static boolean hasEventStreamInput(Model model, ServiceShape service) { + public static boolean hasEventStreamInput(Model model, ServiceShape service) { TopDownIndex topDownIndex = TopDownIndex.of(model); Set operations = topDownIndex.getContainedOperations(service); EventStreamIndex eventStreamIndex = EventStreamIndex.of(model); @@ -150,8 +150,7 @@ private static boolean hasEventStreamInput(Model model, ServiceShape service) { return false; } - private static boolean hasEventStreamInput(Model model, ServiceShape service, OperationShape operation) { - EventStreamIndex eventStreamIndex = EventStreamIndex.of(model); - return eventStreamIndex.getInputInfo(operation).isPresent(); + public static boolean hasEventStreamInput(Model model, OperationShape operation) { + return EventStreamIndex.of(model).getInputInfo(operation).isPresent(); } } diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddTranscribeStreamingDependency.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddTranscribeStreamingDependency.java index 1c6a3fd819ac..b519dc3143b0 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddTranscribeStreamingDependency.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddTranscribeStreamingDependency.java @@ -22,8 +22,6 @@ import software.amazon.smithy.aws.traits.ServiceTrait; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.knowledge.EventStreamIndex; -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.TypeScriptSettings; @@ -56,7 +54,8 @@ public List getClientPlugins() { RuntimeClientPlugin.builder() .withConventions(AwsDependency.TRANSCRIBE_STREAMING_MIDDLEWARE.dependency, "TranscribeStreaming", RuntimeClientPlugin.Convention.HAS_MIDDLEWARE) - .operationPredicate((m, s, o) -> isTranscribeStreaming(s) && hasEventStreamInput(m, s, o)) + .operationPredicate((m, s, o) -> isTranscribeStreaming(s) + && AddEventStreamHandlingDependency.hasEventStreamInput(m, o)) .build() ); } @@ -94,11 +93,6 @@ private static boolean isTranscribeStreaming(ServiceShape service) { String serviceId = service.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse(""); return serviceId.equals("Transcribe Streaming"); } - - private static boolean hasEventStreamInput(Model model, ServiceShape service, OperationShape operation) { - EventStreamIndex eventStreamIndex = EventStreamIndex.of(model); - return eventStreamIndex.getInputInfo(operation).isPresent(); - } } diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddWebsocketPlugin.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddWebsocketPlugin.java index a19697f6489f..18961ba273cd 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddWebsocketPlugin.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddWebsocketPlugin.java @@ -24,7 +24,6 @@ import software.amazon.smithy.codegen.core.CodegenException; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.knowledge.EventStreamIndex; import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.ServiceShape; import software.amazon.smithy.typescript.codegen.LanguageTarget; @@ -62,7 +61,8 @@ public List getClientPlugins() { .withConventions(AwsDependency.MIDDLEWARE_WEBSOCKET.dependency, "WebSocket", RuntimeClientPlugin.Convention.HAS_MIDDLEWARE) .additionalPluginFunctionParamsSupplier((m, s, o) -> getPluginFunctionParams(m, s, o)) - .operationPredicate((m, s, o) -> isWebsocketSupported(s) && hasEventStreamRequest(m, o)) + .operationPredicate((m, s, o) -> isWebsocketSupported(s) + && AddEventStreamHandlingDependency.hasEventStreamInput(m, o)) .build(), RuntimeClientPlugin.builder() .withConventions(AwsDependency.MIDDLEWARE_WEBSOCKET.dependency, "WebSocket", @@ -132,11 +132,6 @@ private static boolean isWebsocketSupported(ServiceShape service) { return websocketServices.contains(serviceId); } - private static boolean hasEventStreamRequest(Model model, OperationShape operation) { - EventStreamIndex eventStreamIndex = EventStreamIndex.of(model); - return eventStreamIndex.getInputInfo(operation).isPresent(); - } - private static Map getPluginFunctionParams( Model model, ServiceShape service,