Skip to content

[FEATURE] Support deprecated option in protoc-gen-go-client #101

@hasanMshawrab

Description

@hasanMshawrab

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

  1. Marking legacy API endpoints as deprecated while maintaining backwards compatibility
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgen/go-clientprotoc-gen-go-client (Go HTTP client)v2.0Targeted for v2.0 release

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions