connectrpc / connect-swift

The Swift implementation of Connect: Protobuf RPC that works.
https://connectrpc.com/docs/swift/getting-started
Apache License 2.0
101 stars 20 forks source link

Generate @available annotations on deprecated RPCs #305

Closed eseay closed 3 weeks ago

eseay commented 1 month ago

Essentially a clone of https://github.com/connectrpc/connect-kotlin/issues/333, but for Swift. Examples below largely influenced by that issue in connect-kotlin.

This would be a very helpful enhancement to the library, as it would allow more effective passive communication from services to their dependents about when certain existing functionality is being deprecated.

There is an ongoing discussion in the apple/swift-protobuf library here about adding this functionality to swift-protobuf itself. Given the age of that discussion, I'd like to consider:

syntax="proto3";

service FooService {
  rpc Foo(FooRequest) returns (FooResponse) {
    // Formally marks the service as being deprecated.
    option deprecated = true;
  }
}

message FooRequest {}
message FooResponse {}

Would generate output like:

public protocol FooServiceClientInterface: Sendable {

-    @available(iOS 13, *)
+    @available(iOS, introduced: 13, deprecated: 13)
    func `foo`(request: FooRequest, headers: Connect.Headers) async -> ResponseMessage<FooResponse>
}

There are obviously a few more details to this that we have to consider for other function types, as this only demonstrates a proposed change for the async functions, but all adjustments would be fundamentally similar in nature.

rebello95 commented 1 month ago

Thanks for opening this @eseay!

Supporting the deprecated option makes a lot of sense to me, and I think it'd be a good addition to Connect-Swift.

Is this something that the Connect community would like to try to revitalize? Do the challenges that prevented the feature from being implemented some years ago still exist?

Can you comment on the upstream SwiftProtobuf issue you linked to in order to see if anything has changed on their end?

Is there merit in adding this functionality to the connect-swift plugin for its generated services in the absence of it being implemented for models and properties in swift-protobuf?

I think so! We should be able to generate this at least for RPCs (and probably services, though we'd need to see if we run into a similar issue as SwiftProtobuf with the generated protocols and their class implementations). Are you interested in doing some of this exploration?

rebello95 commented 1 month ago

we'd need to see if we run into a similar issue as SwiftProtobuf with the generated protocols and their class implementations)

Did a quick test, and I think we should be good on this

Screenshot 2024-10-03 at 7 59 44 PM Screenshot 2024-10-03 at 7 59 57 PM