diff --git a/Package.swift b/Package.swift index 04afd62..f093651 100644 --- a/Package.swift +++ b/Package.swift @@ -38,8 +38,8 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio", from: "2.51.0"), - .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.17.0"), + .package(url: "https://github.com/apple/swift-nio", from: "2.58.0"), + .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"), .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.3")), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 35cb654..1c5c27a 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -15,31 +15,24 @@ import OpenAPIRuntime import AsyncHTTPClient import NIOCore import NIOHTTP1 -import Foundation import NIOFoundationCompat +#if canImport(Darwin) +import Foundation +#else +@preconcurrency import struct Foundation.URL +import struct Foundation.URLComponents +import struct Foundation.Data +import protocol Foundation.LocalizedError +#endif /// A client transport that performs HTTP operations using the HTTPClient type /// provided by the AsyncHTTPClient library. /// /// ### Use the AsyncHTTPClient transport /// -/// Create the underlying HTTP client: -/// -/// let httpClient = HTTPClient(eventLoopGroupProvider: .createNew) -/// -/// Either store a reference to the client elsewhere and shut it down during -/// cleanup, or add a defer block if the client is only used in the current -/// scope: -/// -/// defer { -/// try! httpClient.syncShutdown() -/// } +/// Instantiate the transport: /// -/// Instantiate the transport and provide the HTTP client to it: -/// -/// let transport = AsyncHTTPClientTransport( -/// configuration: .init(client: httpClient) -/// ) +/// let transport = AsyncHTTPClientTransport() /// /// Create the base URL of the server to call using your client. If the server /// URL was defined in the OpenAPI document, you find a generated method for it @@ -61,6 +54,12 @@ import NIOFoundationCompat /// /// let response = try await client.checkHealth(.init()) /// // ... +/// +/// ### Provide a custom Client +/// +/// The ``AsyncHTTPClientTransport/Configuration-swift.struct`` type allows you +/// to provide a custom `HTTPClient` and tweak behaviors such as the default +/// timeout. public struct AsyncHTTPClientTransport: ClientTransport { /// A set of configuration values for the AsyncHTTPClient transport. @@ -76,7 +75,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// - Parameters: /// - client: The underlying client used to perform HTTP operations. /// - timeout: The request timeout, defaults to 1 minute. - public init(client: HTTPClient, timeout: TimeAmount = .minutes(1)) { + public init(client: HTTPClient = .init(), timeout: TimeAmount = .minutes(1)) { self.client = client self.timeout = timeout } diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index b81fd02..f110257 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -63,7 +63,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { } func testConvertResponse() async throws { - let httpResponse: HTTPClientResponse = .init( + let httpResponse = HTTPClientResponse( status: .ok, headers: [ "content-type": "application/json" @@ -83,7 +83,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { func testSend() async throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) - let httpClient: HTTPClient = .init( + let httpClient = HTTPClient( eventLoopGroupProvider: .shared(eventLoopGroup), configuration: .init() ) diff --git a/docker/docker-compose.2204.58.yaml b/docker/docker-compose.2204.58.yaml index eb4be59..eca0761 100644 --- a/docker/docker-compose.2204.58.yaml +++ b/docker/docker-compose.2204.58.yaml @@ -13,6 +13,7 @@ services: environment: - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: image: *image diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml index a475877..1ac8741 100644 --- a/docker/docker-compose.2204.59.yaml +++ b/docker/docker-compose.2204.59.yaml @@ -12,6 +12,7 @@ services: environment: - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: image: *image diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml index 31dbe00..b1443e6 100644 --- a/docker/docker-compose.2204.main.yaml +++ b/docker/docker-compose.2204.main.yaml @@ -12,6 +12,7 @@ services: environment: - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: image: *image diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 994d8b4..055978f 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -30,7 +30,7 @@ services: test: <<: *common - command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-}" + command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} $${STRICT_CONCURRENCY_ARG-}" shell: <<: *common