googleapis / api-linter

A linter for APIs defined in protocol buffers.
https://linter.aip.dev/
Apache License 2.0
600 stars 144 forks source link

Q: AIP-151: dont error on custom operation method #1428

Closed loeffel-io closed 2 months ago

loeffel-io commented 2 months ago

As mentioned here you can add custom bindings. This sounds to me that we can create our own GetOperation/ListOperations method inside our own GrpcService like:

  rpc GetOperation(GetOperationRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/emails/*/operations/*}"
    };
    option (google.api.method_signature) = "name";
  }

but this will fail with

- file_path: mindful/earth/email/v1/email.proto
  problems:
    - message: Methods returning an LRO must include the operation_info annotation.
      location:
        start_position:
            line_number: 77
            column_number: 3
        end_position:
            line_number: 82
            column_number: 3
        path: mindful/earth/email/v1/email.proto
      rule_id: core::0151::operation-info
      rule_doc_uri: https://linter.aip.dev/151/operation-info

Maybe i can get some insights here, thank you 🙏

loeffel-io commented 2 months ago

I think i am wrong here, sounds like i must use just implement the whole longrunning service

noahdietz commented 2 months ago

I think i am wrong here, sounds like i must use just implement the whole longrunning service

You are on the right track here.

Google services do not redefine the google.longrunning.Operations service directly in their own service protos. Instead, they implement it, and register their google.longrunning.Operations server implementation on their endpoint, just like one would do with implementing & registering their own gRPC service implementation.

As such, we don't see the proto definition you've included above in the .proto files being linted, so the assumption is that if an RPC returns a google.longrunning.Operation, it is leveraging the Operations service, not implementing it, and needs to conform to AIP-151.

Closing, but feel free to follow up with questions!

loeffel-io commented 2 months ago

Thank you very much @noahdietz for your answer!

Google services do not redefine the google.longrunning.Operations service directly in their own service protos. Instead, they implement it, and register their google.longrunning.Operations server implementation on their endpoint, just like one would do with implementing & registering their own gRPC service implementation.

Just did this