Skip to content

Commit 51dc5d1

Browse files
authored
Deprecation warnings not emitted when calling operations that are deprecated (#153)
Deprecation warnings not emitted when calling operations that are deprecated ### Motivation Fixes #149. Turns out that when a function is deprecated in a protocol, then calling the function on a concrete type that conforms to that protocol does _not_ emit a warning unless the function _implementation_ is also annotated as deprecated. ### Modifications This PR emits deprecation annotations for the client and server implementations of `APIProtocol`'s functions. ### Result Warnings are now correctly emitted regardless of whether the adopter calls methods on `let client: MyClient` where `MyClient: APIProtocol`, or on `let client: any APIProtocol`, leading to better communication between the author of the OpenAPI document and the adopter of the generated Swift code about the API evolution and future removal of operations. ### Test Plan Adapted integration tests. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #153
1 parent 0fc97c5 commit 51dc5d1

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/translateClientMethod.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ extension ClientFileTranslator {
212212
.expression(sendExpr)
213213
]
214214
)
215+
.deprecate(if: description.operation.deprecated)
215216
)
216217
}
217218
}

Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ extension ServerFileTranslator {
285285
.expression(handleExpr)
286286
]
287287
)
288+
.deprecate(if: description.operation.deprecated)
288289
)
289290

290291
return (registerCall, functionDecl)

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ public struct Client: APIProtocol {
213213
}
214214
/// - Remark: HTTP `POST /probe/`.
215215
/// - Remark: Generated from `#/paths//probe//post(probe)`.
216-
public func probe(_ input: Operations.probe.Input) async throws -> Operations.probe.Output {
216+
@available(*, deprecated) public func probe(_ input: Operations.probe.Input) async throws
217+
-> Operations.probe.Output
218+
{
217219
try await client.send(
218220
input: input,
219221
forOperation: Operations.probe.id,

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Server.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
272272
}
273273
/// - Remark: HTTP `POST /probe/`.
274274
/// - Remark: Generated from `#/paths//probe//post(probe)`.
275-
func probe(request: Request, metadata: ServerRequestMetadata) async throws -> Response {
275+
@available(*, deprecated) func probe(request: Request, metadata: ServerRequestMetadata)
276+
async throws -> Response
277+
{
276278
try await handle(
277279
request: request,
278280
with: metadata,

Tests/PetstoreConsumerTests/Test_Client.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ final class Test_Client: XCTestCase {
341341
}
342342
}
343343

344+
@available(*, deprecated)
344345
func testProbe_204() async throws {
345346
transport = .init { request, baseURL, operationID in
346347
XCTAssertEqual(operationID, "probe")
@@ -359,6 +360,7 @@ final class Test_Client: XCTestCase {
359360
}
360361
}
361362

363+
@available(*, deprecated)
362364
func testProbe_undocumented() async throws {
363365
transport = .init { request, baseURL, operationID in
364366
.init(statusCode: 503)

0 commit comments

Comments
 (0)