Commit cbfac0a
authored
Add deprecation annotations for RPCs marked "deprecated=true" (#316)
This enhances the `ConnectClientGenerator` to inspect the `deprecated`
option and annotate the generated service functions accordingly.
- For async/await functions, the existing `@available` annotation, which
only exists for iOS, is adjusted accordingly to introduce and deprecate
the function at v13, since that is when concurrency was first made
available.
- @rebello95 should we consider adjusting both my deprecation annotation
and the existing annotation to account for the other supported platforms
of the library?
- Since no pattern was established for generated callback functions, I
enhanced their generation to include `@available` annotations for all
supported platforms. The "introduced" and "deprecated" versions for
those platforms were determined by the minimum supported version of the
respective platform defined in `Package.swift`.
Adding the following RPC...
```proto
rpc SayDeprecated(SayRequest) returns (SayResponse) {
option idempotency_level = NO_SIDE_EFFECTS;
option deprecated = true;
}
```
...to the ElizaService defined in the [examples-go
repository](https://github.com/connectrpc/examples-go/blob/main/proto/connectrpc/eliza/v1/eliza.proto),
from which the Eliza sample app sources are generated, and regenerating
the Swift service (setting `GenerateCallbackMethods=true` to also
demonstrate callback behavior) yields the following result:
```swift
@available(iOS, introduced: 12, deprecated: 12, message: "This function has been marked deprecated.")
@available(macOS, introduced: 10.15, deprecated: 10.15, message: "This function has been marked deprecated.")
@available(tvOS, introduced: 13, deprecated: 13, message: "This function has been marked deprecated.")
@available(watchOS, introduced: 6, deprecated: 6, message: "This function has been marked deprecated.")
@discardableResult
func `sayDeprecated`(request: Connectrpc_Eliza_V1_SayRequest, headers: Connect.Headers, completion: @escaping @sendable (ResponseMessage<Connectrpc_Eliza_V1_SayResponse>) -> Void) -> Connect.Cancelable
@available(iOS, introduced: 13, deprecated: 13, message: "This function has been marked deprecated.")
func `sayDeprecated`(request: Connectrpc_Eliza_V1_SayRequest, headers: Connect.Headers) async -> ResponseMessage<Connectrpc_Eliza_V1_SayResponse>
```
The generated code for the existing `Say` RPC remains unchanged:
```swift
/// Say is a unary RPC. Eliza responds to the prompt with a single sentence.
@discardableResult
func `say`(request: Connectrpc_Eliza_V1_SayRequest, headers: Connect.Headers, completion: @escaping @sendable (ResponseMessage<Connectrpc_Eliza_V1_SayResponse>) -> Void) -> Connect.Cancelable
/// Say is a unary RPC. Eliza responds to the prompt with a single sentence.
@available(iOS 13, *)
func `say`(request: Connectrpc_Eliza_V1_SayRequest, headers: Connect.Headers) async -> ResponseMessage<Connectrpc_Eliza_V1_SayResponse>
```
The same additions have been made to the `ConnectMockGenerator`.
Closes #305
---------
Signed-off-by: Eddie Seay <[email protected]>1 parent 9bed141 commit cbfac0a
File tree
2 files changed
+62
-3
lines changed- Plugins
- ConnectMocksPlugin
- ConnectSwiftPlugin
2 files changed
+62
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
153 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
219 | 224 | | |
220 | 225 | | |
221 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
222 | 251 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
122 | 125 | | |
123 | 126 | | |
124 | 127 | | |
| |||
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
136 | | - | |
| 139 | + | |
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
| |||
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
146 | 152 | | |
147 | 153 | | |
148 | 154 | | |
| |||
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
165 | | - | |
| 171 | + | |
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
| |||
201 | 207 | | |
202 | 208 | | |
203 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
204 | 234 | | |
205 | 235 | | |
206 | 236 | | |
| |||
0 commit comments