From 28d4bb2445474d20d820877050bbf16b6a0f59b1 Mon Sep 17 00:00:00 2001 From: noahdietz Date: Tue, 16 Nov 2021 13:34:19 -0800 Subject: [PATCH] feat: include server streaming in rest descriptor --- src/Generation/MethodDetails.php | 5 +++++ src/Generation/ResourcesGenerator.php | 2 +- .../BasicServerStreaming/basic-server-streaming.proto | 8 +++++++- .../basic_server_streaming_rest_client_config.php | 10 +++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Generation/MethodDetails.php b/src/Generation/MethodDetails.php index 20305c333..345864408 100644 --- a/src/Generation/MethodDetails.php +++ b/src/Generation/MethodDetails.php @@ -535,6 +535,11 @@ public function isStreaming(): bool $this->methodType === static::CLIENT_STREAMING; } + public function isServerStreaming(): bool + { + return $this->methodType === static::SERVER_STREAMING; + } + public function isMixin(): bool { return $this->mixinServiceFullname !== null; diff --git a/src/Generation/ResourcesGenerator.php b/src/Generation/ResourcesGenerator.php index 81f0c06e5..c4caf11d6 100644 --- a/src/Generation/ResourcesGenerator.php +++ b/src/Generation/ResourcesGenerator.php @@ -210,7 +210,7 @@ public static function generateRestConfig(ServiceDetails $serviceDetails, Servic private static function compileRestConfigInterfaces(ServiceDetails $serviceDetails, ServiceYamlConfig $serviceYamlConfig) { return $serviceDetails->methods - ->filter(fn ($method) => !is_null($method->httpRule) && !$method->isStreaming() && !$method->isMixin()) + ->filter(fn ($method) => !is_null($method->httpRule) && ($method->isServerStreaming() || !$method->isStreaming()) && !$method->isMixin()) ->map(fn ($method) => [$serviceDetails->serviceName, $method, $method->httpRule]) ->concat($serviceYamlConfig->httpRules->map(fn ($x) => [ Vector::new(explode('.', $x->getSelector()))->skipLast(1)->join('.'), diff --git a/tests/Unit/ProtoTests/BasicServerStreaming/basic-server-streaming.proto b/tests/Unit/ProtoTests/BasicServerStreaming/basic-server-streaming.proto index cdec4bdf4..3e0a3136c 100644 --- a/tests/Unit/ProtoTests/BasicServerStreaming/basic-server-streaming.proto +++ b/tests/Unit/ProtoTests/BasicServerStreaming/basic-server-streaming.proto @@ -4,13 +4,19 @@ package testing.basicserverstreaming; option php_namespace = "Testing\\BasicServerStreaming"; +import "google/api/annotations.proto"; import "google/api/client.proto"; import "google/api/field_behavior.proto"; service BasicServerStreaming { option (google.api.default_host) = "serverstreaming.example.com"; - rpc MethodServer(Request) returns(stream Response); + rpc MethodServer(Request) returns(stream Response) { + option (google.api.http) = { + post: "/path:serverStreaming" + body: "*" + }; + }; rpc MethodEmpty(EmptyRequest) returns(stream Response); } diff --git a/tests/Unit/ProtoTests/BasicServerStreaming/out/src/resources/basic_server_streaming_rest_client_config.php b/tests/Unit/ProtoTests/BasicServerStreaming/out/src/resources/basic_server_streaming_rest_client_config.php index f066b83ba..df28fbaf7 100644 --- a/tests/Unit/ProtoTests/BasicServerStreaming/out/src/resources/basic_server_streaming_rest_client_config.php +++ b/tests/Unit/ProtoTests/BasicServerStreaming/out/src/resources/basic_server_streaming_rest_client_config.php @@ -1,5 +1,13 @@ [], + 'interfaces' => [ + 'testing.basicserverstreaming.BasicServerStreaming' => [ + 'MethodServer' => [ + 'method' => 'post', + 'uriTemplate' => '/path:serverStreaming', + 'body' => '*', + ], + ], + ], ];