-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Is your feature request related to a problem? Please describe.
When using option deprecated = true; on an RPC method in a proto file, the generated Go client code does not include the standard Go // Deprecated: comment. This means IDEs and linters don't recognize the method as deprecated.
Describe the solution you'd like
The protoc-gen-go-client generator should check for the deprecated option on RPC methods and add a // Deprecated: comment to the generated Go code.
Describe alternatives you've considered
- Manually adding comments after generation (not sustainable, gets overwritten)
- Using a post-processing script (adds complexity to build process)
Use Cases
- Marking legacy API endpoints as deprecated while maintaining backwards compatibility
- Guiding users to use newer v2 endpoints instead of deprecated v1 endpoints
Proposed API/Interface
Proto file:
rpc SubscribeTradeEvents(Request) returns (Response) {
option deprecated = true;
option (sebuf.http.config) = {
path: "/events/trades"
method: HTTP_METHOD_GET
};
}Current generated code:
// SubscribeTradeEvents calls the SubscribeTradeEvents RPC.
func (c *serviceClient) SubscribeTradeEvents(ctx context.Context, req *Request, opts ...ServiceCallOption) (*Response, error) {Expected generated code:
// Deprecated: SubscribeTradeEvents is deprecated.
// SubscribeTradeEvents calls the SubscribeTradeEvents RPC.
func (c *serviceClient) SubscribeTradeEvents(ctx context.Context, req *Request, opts ...ServiceCallOption) (*Response, error) {Implementation Suggestion
In internal/clientgen/annotations.go, add:
func isMethodDeprecated(method *protogen.Method) bool {
options := method.Desc.Options()
if options == nil {
return false
}
methodOptions, ok := options.(*descriptorpb.MethodOptions)
if !ok {
return false
}
return methodOptions.GetDeprecated()
}In internal/clientgen/generator.go, modify generateRPCMethodSignature() (line ~439):
if isMethodDeprecated(method) {
gf.P("// Deprecated: ", cfg.methodName, " is deprecated.")
}Impact on Existing Code
- This is a breaking change
- This is backwards compatible
- This requires migration steps
Additional Context
The protobuf deprecated option is a standard field in google.protobuf.MethodOptions. The standard Go protobuf generator (protoc-gen-go) respects this option, so it would be consistent for protoc-gen-go-client to do the same.
Are you willing to contribute this feature?
- Yes, I can implement this feature
- Yes, but I would need guidance
- No, but I can help test it
- No
Label: enhancement