Skip to content

Commit 09ae808

Browse files
authored
Use correct naming for making async calls (#1365)
Motivation: Generated 'makeMethodCall' functions on the async client use the casing of 'Method' as it is defined in the .proto file. Methods are defined in the proto file with 'UpperCamel' casing, so 'makeUpperCamelCall' is correctly cased. However a 'lowerCamel' method would be generated as 'makelowerCamelCall'. We should instead coerce it to be 'makeLowerCamelCall'. We missed this in other areas too, as an example, for interceptors we will generate 'makelowerCamelCallInterceptors'. Unfortunately we can't change this one without the risk of breaking adopters. However, since async is yet to be stable API we can fix this one. Modifications: - Use upper camel casing for 'makeMethodCall' function names Result: Better naming.
1 parent b0e710c commit 09ae808

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extension Generator {
5454
}
5555

5656
self.printFunction(
57-
name: "make\(self.method.name)Call",
57+
name: self.methodMakeFunctionCallName,
5858
arguments: arguments,
5959
returnType: "\(callType)<\(self.methodInputName), \(self.methodOutputName)>",
6060
bodyBuilder: nil
@@ -101,7 +101,7 @@ extension Generator {
101101
switch rpcType {
102102
case .unary, .serverStreaming:
103103
self.printFunction(
104-
name: "make\(self.method.name)Call",
104+
name: self.methodMakeFunctionCallName,
105105
arguments: [
106106
"_ request: \(self.methodInputName)",
107107
"callOptions: \(Types.clientCallOptions)? = nil",
@@ -121,7 +121,7 @@ extension Generator {
121121

122122
case .clientStreaming, .bidirectionalStreaming:
123123
self.printFunction(
124-
name: "make\(self.method.name)Call",
124+
name: self.methodMakeFunctionCallName,
125125
arguments: ["callOptions: \(Types.clientCallOptions)? = nil"],
126126
returnType: "\(callType)<\(self.methodInputName), \(self.methodOutputName)>",
127127
access: self.access

Sources/protoc-gen-grpc-swift/Generator-Names.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ extension Generator {
119119
return self.sanitize(fieldName: name)
120120
}
121121

122+
internal var methodMakeFunctionCallName: String {
123+
let name: String
124+
125+
if self.options.keepMethodCasing {
126+
name = self.method.name
127+
} else {
128+
name = NamingUtils.toUpperCamelCase(self.method.name)
129+
}
130+
131+
let fnName = "make\(name)Call"
132+
return self.sanitize(fieldName: fnName)
133+
}
134+
122135
internal func sanitize(fieldName string: String) -> String {
123136
if quotableFieldNames.contains(string) {
124137
return "`\(string)`"

0 commit comments

Comments
 (0)