Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecated annotations on shorthand functions for deprecated operations #384

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1868,46 +1868,50 @@ 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.
content:
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.
content:
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))
}
}
"""
Expand Down