From 4276acee275a04af47b0cc844229c3e0b1a1ac0a Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Thu, 7 Sep 2023 11:01:59 -0700 Subject: [PATCH] Add leading slash to generated RPC paths This updates generated RPC paths to include leading slashes, which is in line with what `connect-go` does. It also resolves issues with adding path components to the `host` flagged in https://github.com/bufbuild/connect-swift/issues/161. --- .../GeneratedSources/eliza.connect.swift | 6 +- .../MethodDescriptor+Extensions.swift | 2 +- .../Generated/grpc/testing/test.connect.swift | 80 +++++++++---------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Examples/ElizaSharedSources/GeneratedSources/eliza.connect.swift b/Examples/ElizaSharedSources/GeneratedSources/eliza.connect.swift index 5addaace..cf4b6efe 100644 --- a/Examples/ElizaSharedSources/GeneratedSources/eliza.connect.swift +++ b/Examples/ElizaSharedSources/GeneratedSources/eliza.connect.swift @@ -41,16 +41,16 @@ internal final class Connectrpc_Eliza_V1_ElizaServiceClient: Connectrpc_Eliza_V1 @available(iOS 13, *) internal func `say`(request: Connectrpc_Eliza_V1_SayRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "connectrpc.eliza.v1.ElizaService/Say", request: request, headers: headers) + return await self.client.unary(path: "/connectrpc.eliza.v1.ElizaService/Say", request: request, headers: headers) } @available(iOS 13, *) internal func `converse`(headers: Connect.Headers = [:]) -> any Connect.BidirectionalAsyncStreamInterface { - return self.client.bidirectionalStream(path: "connectrpc.eliza.v1.ElizaService/Converse", headers: headers) + return self.client.bidirectionalStream(path: "/connectrpc.eliza.v1.ElizaService/Converse", headers: headers) } @available(iOS 13, *) internal func `introduce`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface { - return self.client.serverOnlyStream(path: "connectrpc.eliza.v1.ElizaService/Introduce", headers: headers) + return self.client.serverOnlyStream(path: "/connectrpc.eliza.v1.ElizaService/Introduce", headers: headers) } } diff --git a/Plugins/ConnectPluginUtilities/MethodDescriptor+Extensions.swift b/Plugins/ConnectPluginUtilities/MethodDescriptor+Extensions.swift index c9dd97db..8a47ebbe 100644 --- a/Plugins/ConnectPluginUtilities/MethodDescriptor+Extensions.swift +++ b/Plugins/ConnectPluginUtilities/MethodDescriptor+Extensions.swift @@ -16,7 +16,7 @@ import SwiftProtobufPluginLibrary extension MethodDescriptor { public var methodPath: String { - return "\(self.service.servicePath)/\(self.name)" + return "/\(self.service.servicePath)/\(self.name)" } public func name(using options: GeneratorOptions) -> String { diff --git a/Tests/ConnectLibraryTests/Generated/grpc/testing/test.connect.swift b/Tests/ConnectLibraryTests/Generated/grpc/testing/test.connect.swift index 18a6df6a..c85d3f2b 100644 --- a/Tests/ConnectLibraryTests/Generated/grpc/testing/test.connect.swift +++ b/Tests/ConnectLibraryTests/Generated/grpc/testing/test.connect.swift @@ -126,106 +126,106 @@ internal final class Grpc_Testing_TestServiceClient: Grpc_Testing_TestServiceCli @discardableResult internal func `emptyCall`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.TestService/EmptyCall", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.TestService/EmptyCall", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `emptyCall`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.TestService/EmptyCall", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.TestService/EmptyCall", request: request, headers: headers) } @discardableResult internal func `unaryCall`(request: Grpc_Testing_SimpleRequest, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.TestService/UnaryCall", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.TestService/UnaryCall", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `unaryCall`(request: Grpc_Testing_SimpleRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.TestService/UnaryCall", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.TestService/UnaryCall", request: request, headers: headers) } @discardableResult internal func `failUnaryCall`(request: Grpc_Testing_SimpleRequest, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.TestService/FailUnaryCall", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.TestService/FailUnaryCall", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `failUnaryCall`(request: Grpc_Testing_SimpleRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.TestService/FailUnaryCall", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.TestService/FailUnaryCall", request: request, headers: headers) } @discardableResult internal func `cacheableUnaryCall`(request: Grpc_Testing_SimpleRequest, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.TestService/CacheableUnaryCall", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.TestService/CacheableUnaryCall", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `cacheableUnaryCall`(request: Grpc_Testing_SimpleRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.TestService/CacheableUnaryCall", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.TestService/CacheableUnaryCall", request: request, headers: headers) } internal func `streamingOutputCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.ServerOnlyStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.TestService/StreamingOutputCall", headers: headers, onResult: onResult) + return self.client.serverOnlyStream(path: "/grpc.testing.TestService/StreamingOutputCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `streamingOutputCall`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.TestService/StreamingOutputCall", headers: headers) + return self.client.serverOnlyStream(path: "/grpc.testing.TestService/StreamingOutputCall", headers: headers) } internal func `failStreamingOutputCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.ServerOnlyStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.TestService/FailStreamingOutputCall", headers: headers, onResult: onResult) + return self.client.serverOnlyStream(path: "/grpc.testing.TestService/FailStreamingOutputCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `failStreamingOutputCall`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.TestService/FailStreamingOutputCall", headers: headers) + return self.client.serverOnlyStream(path: "/grpc.testing.TestService/FailStreamingOutputCall", headers: headers) } internal func `streamingInputCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.ClientOnlyStreamInterface { - return self.client.clientOnlyStream(path: "grpc.testing.TestService/StreamingInputCall", headers: headers, onResult: onResult) + return self.client.clientOnlyStream(path: "/grpc.testing.TestService/StreamingInputCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `streamingInputCall`(headers: Connect.Headers = [:]) -> any Connect.ClientOnlyAsyncStreamInterface { - return self.client.clientOnlyStream(path: "grpc.testing.TestService/StreamingInputCall", headers: headers) + return self.client.clientOnlyStream(path: "/grpc.testing.TestService/StreamingInputCall", headers: headers) } internal func `fullDuplexCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.BidirectionalStreamInterface { - return self.client.bidirectionalStream(path: "grpc.testing.TestService/FullDuplexCall", headers: headers, onResult: onResult) + return self.client.bidirectionalStream(path: "/grpc.testing.TestService/FullDuplexCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `fullDuplexCall`(headers: Connect.Headers = [:]) -> any Connect.BidirectionalAsyncStreamInterface { - return self.client.bidirectionalStream(path: "grpc.testing.TestService/FullDuplexCall", headers: headers) + return self.client.bidirectionalStream(path: "/grpc.testing.TestService/FullDuplexCall", headers: headers) } internal func `halfDuplexCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.BidirectionalStreamInterface { - return self.client.bidirectionalStream(path: "grpc.testing.TestService/HalfDuplexCall", headers: headers, onResult: onResult) + return self.client.bidirectionalStream(path: "/grpc.testing.TestService/HalfDuplexCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `halfDuplexCall`(headers: Connect.Headers = [:]) -> any Connect.BidirectionalAsyncStreamInterface { - return self.client.bidirectionalStream(path: "grpc.testing.TestService/HalfDuplexCall", headers: headers) + return self.client.bidirectionalStream(path: "/grpc.testing.TestService/HalfDuplexCall", headers: headers) } @discardableResult internal func `unimplementedCall`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.TestService/UnimplementedCall", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.TestService/UnimplementedCall", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `unimplementedCall`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.TestService/UnimplementedCall", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.TestService/UnimplementedCall", request: request, headers: headers) } internal func `unimplementedStreamingOutputCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.ServerOnlyStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.TestService/UnimplementedStreamingOutputCall", headers: headers, onResult: onResult) + return self.client.serverOnlyStream(path: "/grpc.testing.TestService/UnimplementedStreamingOutputCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `unimplementedStreamingOutputCall`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.TestService/UnimplementedStreamingOutputCall", headers: headers) + return self.client.serverOnlyStream(path: "/grpc.testing.TestService/UnimplementedStreamingOutputCall", headers: headers) } internal enum Metadata { @@ -275,21 +275,21 @@ internal final class Grpc_Testing_UnimplementedServiceClient: Grpc_Testing_Unimp @discardableResult internal func `unimplementedCall`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.UnimplementedService/UnimplementedCall", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.UnimplementedService/UnimplementedCall", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `unimplementedCall`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.UnimplementedService/UnimplementedCall", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.UnimplementedService/UnimplementedCall", request: request, headers: headers) } internal func `unimplementedStreamingOutputCall`(headers: Connect.Headers = [:], onResult: @escaping (Connect.StreamResult) -> Void) -> any Connect.ServerOnlyStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.UnimplementedService/UnimplementedStreamingOutputCall", headers: headers, onResult: onResult) + return self.client.serverOnlyStream(path: "/grpc.testing.UnimplementedService/UnimplementedStreamingOutputCall", headers: headers, onResult: onResult) } @available(iOS 13, *) internal func `unimplementedStreamingOutputCall`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface { - return self.client.serverOnlyStream(path: "grpc.testing.UnimplementedService/UnimplementedStreamingOutputCall", headers: headers) + return self.client.serverOnlyStream(path: "/grpc.testing.UnimplementedService/UnimplementedStreamingOutputCall", headers: headers) } internal enum Metadata { @@ -326,22 +326,22 @@ internal final class Grpc_Testing_ReconnectServiceClient: Grpc_Testing_Reconnect @discardableResult internal func `start`(request: Grpc_Testing_ReconnectParams, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.ReconnectService/Start", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.ReconnectService/Start", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `start`(request: Grpc_Testing_ReconnectParams, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.ReconnectService/Start", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.ReconnectService/Start", request: request, headers: headers) } @discardableResult internal func `stop`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.ReconnectService/Stop", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.ReconnectService/Stop", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `stop`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.ReconnectService/Stop", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.ReconnectService/Stop", request: request, headers: headers) } internal enum Metadata { @@ -382,22 +382,22 @@ internal final class Grpc_Testing_LoadBalancerStatsServiceClient: Grpc_Testing_L @discardableResult internal func `getClientStats`(request: Grpc_Testing_LoadBalancerStatsRequest, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.LoadBalancerStatsService/GetClientStats", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.LoadBalancerStatsService/GetClientStats", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `getClientStats`(request: Grpc_Testing_LoadBalancerStatsRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.LoadBalancerStatsService/GetClientStats", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.LoadBalancerStatsService/GetClientStats", request: request, headers: headers) } @discardableResult internal func `getClientAccumulatedStats`(request: Grpc_Testing_LoadBalancerAccumulatedStatsRequest, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.LoadBalancerStatsService/GetClientAccumulatedStats", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.LoadBalancerStatsService/GetClientAccumulatedStats", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `getClientAccumulatedStats`(request: Grpc_Testing_LoadBalancerAccumulatedStatsRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.LoadBalancerStatsService/GetClientAccumulatedStats", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.LoadBalancerStatsService/GetClientAccumulatedStats", request: request, headers: headers) } internal enum Metadata { @@ -434,22 +434,22 @@ internal final class Grpc_Testing_XdsUpdateHealthServiceClient: Grpc_Testing_Xds @discardableResult internal func `setServing`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.XdsUpdateHealthService/SetServing", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.XdsUpdateHealthService/SetServing", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `setServing`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.XdsUpdateHealthService/SetServing", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.XdsUpdateHealthService/SetServing", request: request, headers: headers) } @discardableResult internal func `setNotServing`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.XdsUpdateHealthService/SetNotServing", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.XdsUpdateHealthService/SetNotServing", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `setNotServing`(request: Grpc_Testing_Empty, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.XdsUpdateHealthService/SetNotServing", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.XdsUpdateHealthService/SetNotServing", request: request, headers: headers) } internal enum Metadata { @@ -482,12 +482,12 @@ internal final class Grpc_Testing_XdsUpdateClientConfigureServiceClient: Grpc_Te @discardableResult internal func `configure`(request: Grpc_Testing_ClientConfigureRequest, headers: Connect.Headers = [:], completion: @escaping (ResponseMessage) -> Void) -> Connect.Cancelable { - return self.client.unary(path: "grpc.testing.XdsUpdateClientConfigureService/Configure", request: request, headers: headers, completion: completion) + return self.client.unary(path: "/grpc.testing.XdsUpdateClientConfigureService/Configure", request: request, headers: headers, completion: completion) } @available(iOS 13, *) internal func `configure`(request: Grpc_Testing_ClientConfigureRequest, headers: Connect.Headers = [:]) async -> ResponseMessage { - return await self.client.unary(path: "grpc.testing.XdsUpdateClientConfigureService/Configure", request: request, headers: headers) + return await self.client.unary(path: "/grpc.testing.XdsUpdateClientConfigureService/Configure", request: request, headers: headers) } internal enum Metadata {