From bd9b1996c282c62e86bd40c3cbd314dff5bcc939 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Fri, 17 Nov 2023 16:17:17 +0000 Subject: [PATCH] Add deprecated annotations on shorthand functions for deprecated operations --- .../translateAPIProtocol.swift | 6 ++- .../SnippetBasedReferenceTests.swift | 48 ++++++++++--------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift index 1e2fd2e2..3b061854 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift @@ -78,7 +78,11 @@ extension TypesFileTranslator { ) ] ) - return .commentable(operation.comment, .function(function)) + if operation.operation.deprecated { + return .commentable(operation.comment, .deprecated(.init(), .function(function))) + } else { + return .commentable(operation.comment, .function(function)) + } } } diff --git a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift index dd20bbb2..6600891e 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift @@ -1868,12 +1868,12 @@ final class SnippetBasedReferenceTests: XCTestCase { ) } - func testPathsSimplestCase() throws { - try self.assertPathsTranslation( - """ - /health: + func testPaths() throws { + let paths = """ + /healthOld: get: - operationId: getHealth + operationId: getHealthOld + deprecated: true responses: '200': description: A success response with a greeting. @@ -1881,21 +1881,9 @@ final class SnippetBasedReferenceTests: XCTestCase { text/plain: schema: type: string - """, - """ - public protocol APIProtocol: Sendable { - func getHealth(_ input: Operations.getHealth.Input) async throws -> Operations.getHealth.Output - } - """ - ) - } - - func testPathsSimplestCaseExtension() throws { - try self.assertPathsTranslationExtension( - """ - /health: + /healthNew: get: - operationId: getHealth + operationId: getHealthNew responses: '200': description: A success response with a greeting. @@ -1903,11 +1891,27 @@ final class SnippetBasedReferenceTests: XCTestCase { text/plain: schema: type: string - """, + """ + try self.assertPathsTranslation( + paths, + """ + public protocol APIProtocol: Sendable { + @available(*, deprecated) + func getHealthOld(_ input: Operations.getHealthOld.Input) async throws -> Operations.getHealthOld.Output + func getHealthNew(_ input: Operations.getHealthNew.Input) async throws -> Operations.getHealthNew.Output + } + """ + ) + try self.assertPathsTranslationExtension( + paths, """ extension APIProtocol { - public func getHealth(headers: Operations.getHealth.Input.Headers = .init()) async throws -> Operations.getHealth.Output { - try await getHealth(Operations.getHealth.Input(headers: headers)) + @available(*, deprecated) + public func getHealthOld(headers: Operations.getHealthOld.Input.Headers = .init()) async throws -> Operations.getHealthOld.Output { + try await getHealthOld(Operations.getHealthOld.Input(headers: headers)) + } + public func getHealthNew(headers: Operations.getHealthNew.Input.Headers = .init()) async throws -> Operations.getHealthNew.Output { + try await getHealthNew(Operations.getHealthNew.Input(headers: headers)) } } """