Browse Source

Rename generated clients from FooServiceClient to FooClient (#736)

Motivation:

Issue #735 highlighted that the naming of generated clients is clunky.
Let's improve it before the API is locked down.

Note: it's possible to create a shim to create fix-its for this by creating a
typealias from the old name to the new name, and then deprecating the
typealias:

```swift
@available(*, deprecated, renamed: "Echo_EchoClient")
typealias Echo_EchoServiceClient = Echo_EchoClient
```

Modifications:

- Update codegen
- Regenerate clients and update usages

Result:

Generate clients have better names
George Barnett 6 years ago
parent
commit
d307bf3a66

+ 3 - 3
Sources/protoc-gen-grpc-swift/Generator-Client.swift

@@ -26,8 +26,8 @@ extension Generator {
   }
 
   private func printServiceClientProtocol() {
-    println("/// Usage: instantiate \(serviceClassName)Client, then call methods of this protocol to make API calls.")
-    println("\(options.visibility.sourceSnippet) protocol \(serviceClassName) {")
+    println("/// Usage: instantiate \(clientClassName), then call methods of this protocol to make API calls.")
+    println("\(options.visibility.sourceSnippet) protocol \(clientProtocolName) {")
     indent()
     for method in service.methods {
       self.method = method
@@ -50,7 +50,7 @@ extension Generator {
   }
 
   private func printServiceClientImplementation() {
-    println("\(access) final class \(serviceClassName)Client: GRPCClient, \(serviceClassName) {")
+    println("\(access) final class \(clientClassName): GRPCClient, \(clientProtocolName) {")
     indent()
     println("\(access) let channel: GRPCChannel")
     println("\(access) var defaultCallOptions: CallOptions")

+ 8 - 0
Sources/protoc-gen-grpc-swift/Generator-Names.swift

@@ -46,6 +46,14 @@ extension Generator {
     return nameForPackageService(file, service) + "Provider"
   }
 
+  internal var clientClassName: String {
+    return nameForPackageService(file, service) + "Client"
+  }
+
+  internal var clientProtocolName: String {
+    return nameForPackageService(file, service) + "ClientProtocol"
+  }
+
   internal var callName: String {
     return nameForPackageServiceMethod(file, service, method) + "Call"
   }