浏览代码

Inline service name into the generated path (#633)

Motivation:

We gave users the option to customise how the path for the RPC was
formatted. The protocol allows this but discourages it.

Modifications:

- Inline the service name into the generated code
- Remove GRPCServiceClient and just use GRPCClient
- Update generated code

Result:

- Users are now discouraged in the strongest possible way to not use
  custom paths.
- Generated code is simpler.
George Barnett 6 年之前
父节点
当前提交
7b7b8c0871
共有 1 个文件被更改,包括 5 次插入6 次删除
  1. 5 6
      Sources/protoc-gen-grpc-swift/Generator-Client.swift

+ 5 - 6
Sources/protoc-gen-grpc-swift/Generator-Client.swift

@@ -50,10 +50,9 @@ extension Generator {
   }
 
   private func printServiceClientImplementation() {
-    println("\(access) final class \(serviceClassName)Client: GRPCServiceClient, \(serviceClassName) {")
+    println("\(access) final class \(serviceClassName)Client: GRPCClient, \(serviceClassName) {")
     indent()
     println("\(access) let connection: ClientConnection")
-    println("\(access) var serviceName: String { return \"\(servicePath)\" }")
     println("\(access) var defaultCallOptions: CallOptions")
     println()
     println("/// Creates a client for the \(servicePath) service.")
@@ -81,7 +80,7 @@ extension Generator {
         println("/// - Returns: A `UnaryCall` with futures for the metadata, status and response.")
         println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions? = nil) -> UnaryCall<\(methodInputName), \(methodOutputName)> {")
         indent()
-        println("return self.makeUnaryCall(path: self.path(forMethod: \"\(method.name)\"),")
+        println("return self.makeUnaryCall(path: \"/\(servicePath)/\(method.name)\",")
         println("                          request: request,")
         println("                          callOptions: callOptions ?? self.defaultCallOptions)")
         outdent()
@@ -97,7 +96,7 @@ extension Generator {
         println("/// - Returns: A `ServerStreamingCall` with futures for the metadata and status.")
         println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions? = nil, handler: @escaping (\(methodOutputName)) -> Void) -> ServerStreamingCall<\(methodInputName), \(methodOutputName)> {")
         indent()
-        println("return self.makeServerStreamingCall(path: self.path(forMethod: \"\(method.name)\"),")
+        println("return self.makeServerStreamingCall(path: \"/\(servicePath)/\(method.name)\",")
         println("                                    request: request,")
         println("                                    callOptions: callOptions ?? self.defaultCallOptions,")
         println("                                    handler: handler)")
@@ -114,7 +113,7 @@ extension Generator {
         println("/// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.")
         println("\(access) func \(methodFunctionName)(callOptions: CallOptions? = nil) -> ClientStreamingCall<\(methodInputName), \(methodOutputName)> {")
         indent()
-        println("return self.makeClientStreamingCall(path: self.path(forMethod: \"\(method.name)\"),")
+        println("return self.makeClientStreamingCall(path: \"/\(servicePath)/\(method.name)\",")
         println("                                    callOptions: callOptions ?? self.defaultCallOptions)")
         outdent()
         println("}")
@@ -130,7 +129,7 @@ extension Generator {
         println("/// - Returns: A `ClientStreamingCall` with futures for the metadata and status.")
         println("\(access) func \(methodFunctionName)(callOptions: CallOptions? = nil, handler: @escaping (\(methodOutputName)) -> Void) -> BidirectionalStreamingCall<\(methodInputName), \(methodOutputName)> {")
         indent()
-        println("return self.makeBidirectionalStreamingCall(path: self.path(forMethod: \"\(method.name)\"),")
+        println("return self.makeBidirectionalStreamingCall(path: \"/\(servicePath)/\(method.name)\",")
         println("                                           callOptions: callOptions ?? self.defaultCallOptions,")
         println("                                           handler: handler)")
         outdent()