-
Notifications
You must be signed in to change notification settings - Fork 426
fix generated method names #2224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/1.x
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR, however, I don't think we can accept it as is.
The incorrect casing has already shipped so changing it now will be a breaking change for any users currently relying on it.
We can, however, generate both variants of the makeX
method (when it's necessary) and deprecate the incorrect version saying that it's been renamed to the new name.
The makeXInterceptors
method is a protocol requirement if I remember correctly so fixing that is more difficult because adding a requirement to the protocol is a breaking change. If we added it we'd also need to add a default implementation. The only sensible thing for the default implementation of the new method to do is call the old and now deprecated method. This also means that the user won't be aware that they need to actually implement the new method.
I think if we're to accept a change for these fixes we should leave makeXInterceptors
as it is and only fix the makeX
methods. The incorrect methods should be kept and be deprecated and just call through to the correctly cased methods.
Unfortunately, both methods are in a protocol. The There are two solutions:
OR
|
This approach isn't tenable; it's still a breaking change.
Yeah, I agree with that, I don't think we need to fix
Given that users don't typically implement |
We can do this, I'd prefer to have anything with a proper name than nothing. The current implementation of These lines are especially a point of interest: so for example So the newly generated wrapping function that uses a proper name also helps to avoid this issue 💪 . |
There's a strong dependency between gRPC Swift and SwiftProtobuf; we can't the major version of SwiftProtobuf without changing the major version of gRPC Swift. SwiftProtobuf also can't change the behavior of that method without potentially breaking its users so it's actually not an issue for gRPC to be using this at all.
Actually This is exactly what that code in SwiftProtobuf is for, and we should use it here as well. |
internal var methodComposableName: String { | ||
var name = method.name | ||
if !options.keepMethodCasing { | ||
name = name.prefix(1).uppercased() + name.dropFirst() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using the camel caser here to make it upper camel-case
printRpcFunctionImplementation(rpcType: rpcType) | ||
printRpcFunctionWrapper(rpcType: rpcType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these should both be printRPC...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also need to agree to and sign the CLA for us to consider this patch.
This PR fixes incorrectly generated method names.
For example:
rpc GRPCUnary(google.protobuf.Empty) returns (google.protobuf.Empty) {}
The plugin correctly generates:
makeGRPCUnaryInterceptors
Methods.gRPCUnary
func gRPCUnary
but incorrectly:
makeGrpcunaryCall
This seems to be the only place with a different logic.
And when using lowercase letters, the interceptor method name is incorrect:
rpc unary(google.protobuf.Empty) returns (FunctionName) {}
The plugin correctly generates:
makeUnaryCall
Methods.unary
func unary
but incorrectly:
makeunaryInterceptors
The PR fixes these two issues by introducing a common logic for
methodMakeFunctionCallName
andmethodInterceptorFactoryName
. The logic is similar to the one inmethodFunctionName
, just that it uppercases the first character instead of lowercasing.Thus, for the given examples the result is:
makeGRPCUnaryCall
andmakeUnaryInterceptors