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

Adopt Sendable throughout API to support -strict-concurrency=complete #22

Merged
merged 17 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion Sources/OpenAPIRuntime/Interface/ClientTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ public protocol ClientMiddleware: Sendable {
/// - operationID: The identifier of the OpenAPI operation.
/// - next: A closure that calls the next middleware, or the transport.
/// - Returns: An HTTP response.
@preconcurrency
MahdiBM marked this conversation as resolved.
Show resolved Hide resolved
func intercept(
_ request: Request,
baseURL: URL,
operationID: String,
next: (Request, URL) async throws -> Response
next: @Sendable (Request, URL) async throws -> Response
) async throws -> Response
}
8 changes: 4 additions & 4 deletions Sources/OpenAPIRuntime/Interface/ServerTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ public protocol ServerTransport {
/// - path: The URL path components, for example `["pets", ":petId"]`.
/// - queryItemNames: The names of query items to be extracted
/// from the request URL that matches the provided HTTP operation.
@preconcurrency
func register(
_ handler: @Sendable @escaping (
Request, ServerRequestMetadata
) async throws -> Response,
_ handler: @Sendable @escaping (Request, ServerRequestMetadata) async throws -> Response,
method: HTTPMethod,
path: [RouterPathComponent],
queryItemNames: Set<String>
Expand Down Expand Up @@ -215,10 +214,11 @@ public protocol ServerMiddleware: Sendable {
/// - operationID: The identifier of the OpenAPI operation.
/// - next: A closure that calls the next middleware, or the transport.
/// - Returns: An HTTP response.
@preconcurrency
func intercept(
_ request: Request,
metadata: ServerRequestMetadata,
operationID: String,
next: (Request, ServerRequestMetadata) async throws -> Response
next: @Sendable (Request, ServerRequestMetadata) async throws -> Response
) async throws -> Response
}
8 changes: 5 additions & 3 deletions Sources/OpenAPIRuntime/Interface/UniversalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ public struct UniversalClient: Sendable {
/// - serializer: Creates an HTTP request from the provided Input value.
/// - deserializer: Creates an Output value from the provided HTTP response.
/// - Returns: The Output value produced by `deserializer`.
@preconcurrency
public func send<OperationInput, OperationOutput>(
input: OperationInput,
forOperation operationID: String,
serializer: (OperationInput) throws -> Request,
deserializer: (Response) throws -> OperationOutput
serializer: @Sendable (OperationInput) throws -> Request,
deserializer: @Sendable (Response) throws -> OperationOutput
) async throws -> OperationOutput {
@Sendable
func wrappingErrors<R>(
work: () async throws -> R,
mapError: (Error) -> Error
Expand Down Expand Up @@ -121,7 +123,7 @@ public struct UniversalClient: Sendable {
makeError(error: error)
}
let response: Response = try await wrappingErrors {
var next: (Request, URL) async throws -> Response = { (_request, _url) in
var next: @Sendable (Request, URL) async throws -> Response = { (_request, _url) in
try await wrappingErrors {
try await transport.send(
_request,
Expand Down
11 changes: 7 additions & 4 deletions Sources/OpenAPIRuntime/Interface/UniversalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ public struct UniversalServer<APIHandler: Sendable>: Sendable {
/// - deserializer: Creates an Input value from the provided HTTP request.
/// - serializer: Creates an HTTP response from the provided Output value.
/// - Returns: The HTTP response produced by `serializer`.
@preconcurrency
public func handle<OperationInput, OperationOutput>(
request: Request,
with metadata: ServerRequestMetadata,
forOperation operationID: String,
using handlerMethod: @escaping (APIHandler) -> ((OperationInput) async throws -> OperationOutput),
deserializer: @escaping (Request, ServerRequestMetadata) throws -> OperationInput,
serializer: @escaping (OperationOutput, Request) throws -> Response
using handlerMethod: @Sendable @escaping (APIHandler) -> ((OperationInput) async throws -> OperationOutput),
deserializer: @Sendable @escaping (Request, ServerRequestMetadata) throws -> OperationInput,
serializer: @Sendable @escaping (OperationOutput, Request) throws -> Response
) async throws -> Response {
@Sendable
func wrappingErrors<R>(
work: () async throws -> R,
mapError: (Error) -> Error
Expand All @@ -102,6 +104,7 @@ public struct UniversalServer<APIHandler: Sendable>: Sendable {
throw mapError(error)
}
}
@Sendable
func makeError(
input: OperationInput? = nil,
output: OperationOutput? = nil,
Expand All @@ -116,7 +119,7 @@ public struct UniversalServer<APIHandler: Sendable>: Sendable {
underlyingError: error
)
}
var next: (Request, ServerRequestMetadata) async throws -> Response = { _request, _metadata in
var next: @Sendable (Request, ServerRequestMetadata) async throws -> Response = { _request, _metadata in
let input: OperationInput = try await wrappingErrors {
try deserializer(_request, _metadata)
} mapError: { error in
Expand Down