From 84cf5f4c6b9557a94dfff72af6d866cadaef6481 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 13 Jun 2023 17:23:07 +0200 Subject: [PATCH 01/40] [Releases] Add a GitHub release config (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Releases] Add a GitHub release config ### Motivation This config helps compose release notes easier. ### Modifications Added a config file that instructs GitHub how to group PRs. ### Result Releases can be mostly generated now. ### Test Plan N/A Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/7 --- .github/release.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/release.yml diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..4d18da5 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,15 @@ +changelog: + categories: + - title: SemVer Major + labels: + - semver/major + - title: SemVer Minor + labels: + - semver/minor + - title: SemVer Patch + labels: + - semver/patch + - title: Other Changes + labels: + - semver/none + - "*" From 32f3ae2f51e4989d540ce7f46d770f224fe51a28 Mon Sep 17 00:00:00 2001 From: Denil Chungath <95201442+denil-ct@users.noreply.github.com> Date: Tue, 13 Jun 2023 20:53:43 +0530 Subject: [PATCH 02/40] Relax deployment target to macOS 10.15 (#6) ### Motivation Relax deployment target to macOS 10.15 ### Modifications - Reduced requirement from macOS 13 to macOS 10.15 - Added the minimum version to readme and documentation ### Result - Users will be able to deploy it on projects with a minimum deployment target of 10.15 --- Package.swift | 4 ++-- README.md | 5 +++++ .../Documentation.docc/Documentation.md | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 1e2e087..d89db3c 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ import PackageDescription let package = Package( name: "swift-openapi-async-http-client", platforms: [ - .macOS(.v13), + .macOS(.v10_15), ], products: [ .library( @@ -29,7 +29,7 @@ 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-openapi-runtime", .upToNextMinor(from: "0.1.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"), ], targets: [ diff --git a/README.md b/README.md index 1c77902..1dad359 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ A client transport that uses the [HTTPClient](https://swift-server.github.io/asy Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). +## Supported platforms and minimum versions + | macOS | Linux | + | :-: | :-: | + | ✅ 10.15+ | ✅ | + ## Usage Add the package dependency in your `Package.swift`: diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index 03ba2b0..517afbe 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -8,6 +8,11 @@ A client transport that uses the [HTTPClient](https://swift-server.github.io/asy Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). +### Supported platforms and minimum versions +| macOS | Linux | +| :-: | :-: | +| ✅ 10.15+ | ✅ | + ### Usage Add the package dependency in your `Package.swift`: From 98213b70f9b8881ebb9aeb2d9e361f52b18796c8 Mon Sep 17 00:00:00 2001 From: Mahdi Bahrami Date: Thu, 13 Jul 2023 11:05:08 +0330 Subject: [PATCH 03/40] Full compatibility with the "ExistentialAny" upcoming feature (#8) Discussed and requested in https://github.com/apple/swift-openapi-generator/pull/99#issuecomment-1630636372 --- Package.swift | 13 +++++++++++-- .../AsyncHTTPClientTransport.swift | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index d89db3c..0c48d93 100644 --- a/Package.swift +++ b/Package.swift @@ -15,6 +15,13 @@ import Foundation import PackageDescription +// General Swift-settings for all targets. +let swiftSettings: [SwiftSetting] = [ + // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md + // Require `any` for existential types. + .enableUpcomingFeature("ExistentialAny") +] + let package = Package( name: "swift-openapi-async-http-client", platforms: [ @@ -39,13 +46,15 @@ let package = Package( .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), .product(name: "AsyncHTTPClient", package: "async-http-client"), .product(name: "NIOFoundationCompat", package: "swift-nio"), - ] + ], + swiftSettings: swiftSettings ), .testTarget( name: "OpenAPIAsyncHTTPClientTests", dependencies: [ "OpenAPIAsyncHTTPClient", - ] + ], + swiftSettings: swiftSettings ), ] ) diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 63b38b4..35cb654 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -115,7 +115,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { public var configuration: Configuration /// Underlying request sender for the transport. - internal let requestSender: HTTPRequestSending + internal let requestSender: any HTTPRequestSending /// Creates a new transport. /// - Parameters: @@ -123,7 +123,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// - requestSender: The underlying request sender. internal init( configuration: Configuration, - requestSender: HTTPRequestSending + requestSender: any HTTPRequestSending ) { self.configuration = configuration self.requestSender = requestSender From 875fecf08b5850f3fe81ae77c2c7566a7c9495bf Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 17 Jul 2023 11:30:12 +0200 Subject: [PATCH 04/40] Disable ExistentialAny temporarily (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disable ExistentialAny temporarily ### Motivation Unfortunately until we adopt 5.9, adding ExistentialAny on upstream packages has unintended consequences for some downstream packages, so disabling for now. Details in https://github.com/apple/swift-openapi-generator/issues/120 ### Modifications Disabled the feature enforcement, but the code changes are there, so downstream adopters can still use them. ### Result We won't be seeing the issue described in https://github.com/apple/swift-openapi-generator/issues/120. ### Test Plan PR CI, which discovered the original issue. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/9 --- Package.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 0c48d93..04afd62 100644 --- a/Package.swift +++ b/Package.swift @@ -16,11 +16,15 @@ import Foundation import PackageDescription // General Swift-settings for all targets. -let swiftSettings: [SwiftSetting] = [ +var swiftSettings: [SwiftSetting] = [] + +#if swift(>=5.9) +swiftSettings.append( // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md // Require `any` for existential types. .enableUpcomingFeature("ExistentialAny") -] +) +#endif let package = Package( name: "swift-openapi-async-http-client", From 762f5e50ef7e342cc8099c0f4bab496fc8d7e237 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 1 Aug 2023 16:14:00 +0200 Subject: [PATCH 05/40] [AHCTransport] Consistent style for initializing local variables (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [AHCTransport] Consistent style for initializing local variables ### Motivation Move to a consistent style when initializing local variables, always use `let foo = Foo(...)` vs `let foo: Foo = .init(...)`. ### Modifications Updated all occurrences of the latter to use the former. ### Result Consistent local variable initialization. ### Test Plan All tests passed. Reviewed by: gjcairo, simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/10 --- .../Test_AsyncHTTPClientTransport.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() ) From 95bb2f8456ccbad2d69460c3a0967c80798a19ac Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Fri, 11 Aug 2023 16:02:13 +0200 Subject: [PATCH 06/40] Enable strict concurrency checking in CI (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable strict concurrency checking in CI ### Motivation To further avoid concurrency bugs, enable complete concurrency checking in CI. ### Modifications Added the compiler flag to the docker-compose scripts. ### Result If a warning of this nature comes up, because we have warnings-as-errors, it'll fail CI. ### Test Plan Locally built without any warnings with the flag enabled. Reviewed by: glbrntt Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/11 --- .../AsyncHTTPClientTransport.swift | 9 ++++++++- docker/docker-compose.2204.58.yaml | 1 + docker/docker-compose.2204.59.yaml | 1 + docker/docker-compose.2204.main.yaml | 1 + docker/docker-compose.yaml | 2 +- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 35cb654..f09fdbb 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -15,8 +15,15 @@ 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. 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 From 91dfd35092f622aedf2f79943293a9cccc25bff3 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 29 Aug 2023 14:45:24 +0200 Subject: [PATCH 07/40] Adopt the new shared HTTP client (#13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adopt the new shared HTTP client ### Motivation Now that SwiftNIO/AsyncHTTPClient have a singleton variant of the `EventLoopGroup`, which allows creating an `HTTPClient` without any argument, let's simplify the initializer of the transport to take advantage of it - bringing it in line with the URLSession transport. ### Modifications Default the HTTPClient to a new one with a default event loop group, and remove the mandatory shutdown call. ### Result Adopters can more easily create the AHC transport. ### Test Plan N/A Reviewed by: dnadoba, glbrntt Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/13 --- Package.swift | 4 +-- .../AsyncHTTPClientTransport.swift | 26 +++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) 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 f09fdbb..1c5c27a 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -30,23 +30,9 @@ import protocol Foundation.LocalizedError /// /// ### Use the AsyncHTTPClient transport /// -/// Create the underlying HTTP client: +/// Instantiate the transport: /// -/// 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 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 @@ -68,6 +54,12 @@ import protocol Foundation.LocalizedError /// /// 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. @@ -83,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 } From 0d9e57945b42e1513c680485bf4df4df3930da3f Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 30 Aug 2023 17:16:36 +0200 Subject: [PATCH 08/40] Prepare being compatible with runtime 0.2.0 release (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare being compatible with runtime 0.2.0 release ### Motivation Runtime 0.2.0 is compatible with 0.1.3+ in the APIs adopted in the transport, so just reflect that in the manifest. ### Modifications Increased the supported runtime range to include 0.2.x. ### Result Once released, folks will be able to use 0.1.x of this transport with both 0.1.x and 0.2.x of runtime. ### Test Plan Will be manually tested once runtime 0.2.0 is released. Reviewed by: gjcairo Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/12 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index f093651..b7d99bb 100644 --- a/Package.swift +++ b/Package.swift @@ -40,7 +40,7 @@ let package = Package( dependencies: [ .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-openapi-runtime", "0.1.3" ..< "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], targets: [ From 902cfc7420390a28fd578d556317e048fa746575 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 31 Aug 2023 14:26:14 +0200 Subject: [PATCH 09/40] Docs fixes (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docs fixes ### Motivation Docs should be correct. ### Modifications Update docs to reflect the new version. ### Result N/A ### Test Plan N/A Reviewed by: dnadoba Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/14 --- README.md | 2 +- .../OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1dad359..b9d442c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add the package dependency in your `Package.swift`: ```swift .package( url: "https://github.com/swift-server/swift-openapi-async-http-client", - .upToNextMinor(from: "0.1.0") + .upToNextMinor(from: "0.2.0") ), ``` diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index 517afbe..054a552 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -20,7 +20,7 @@ Add the package dependency in your `Package.swift`: ```swift .package( url: "https://github.com/swift-server/swift-openapi-async-http-client", - .upToNextMinor(from: "0.1.0") + .upToNextMinor(from: "0.2.0") ), ``` From 7e40bff52db90778748d6f55331d1d6e75389720 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 7 Sep 2023 14:53:14 +0200 Subject: [PATCH 10/40] Fix double encoding of path parameters (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix double encoding of path parameters ### Motivation Fixes https://github.com/apple/swift-openapi-generator/issues/251. ### Modifications Use the already escaped path setter on `URLComponents` to avoid the second encoding pass. ### Result Path parameters that needed escaping are only escaped once, not twice. ### Test Plan Adapted the existing unit test to cover a path item that needs escaping. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/15 --- Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift | 2 +- .../Test_AsyncHTTPClientTransport.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 1c5c27a..748c093 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -161,7 +161,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { guard var baseUrlComponents = URLComponents(string: baseURL.absoluteString) else { throw Error.invalidRequestURL(request: request, baseURL: baseURL) } - baseUrlComponents.path += request.path + baseUrlComponents.percentEncodedPath += request.path baseUrlComponents.percentEncodedQuery = request.query guard let url = baseUrlComponents.url else { throw Error.invalidRequestURL(request: request, baseURL: baseURL) diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index f110257..03b732b 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -38,7 +38,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { func testConvertRequest() throws { let request: OpenAPIRuntime.Request = .init( - path: "/hello/Maria", + path: "/hello%20world/Maria", query: "greeting=Howdy", method: .post, headerFields: [ @@ -50,7 +50,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { request, baseURL: try XCTUnwrap(URL(string: "http://example.com/api/v1")) ) - XCTAssertEqual(httpRequest.url, "http://example.com/api/v1/hello/Maria?greeting=Howdy") + XCTAssertEqual(httpRequest.url, "http://example.com/api/v1/hello%20world/Maria?greeting=Howdy") XCTAssertEqual(httpRequest.method, .POST) XCTAssertEqual( httpRequest.headers, From f228a33bdf8c4e1bb8d069c22a0df5bc8f4c93fb Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 18 Sep 2023 15:38:11 +0200 Subject: [PATCH 11/40] Adopt a custom shared client (#18) ### Motivation We previously defaulted the HTTPClient to .init(), but that's not correct as it was never getting shut down. ### Modifications Instead of creating a new client, just introduce our own shared one and use that as the default value. Once AHC provides a shared client, we can default to that in the configuration initializer. ### Result No more crashing clients on dealloc. ### Test Plan All tests pass. --------- Co-authored-by: David Nadoba --- .../AsyncHTTPClientTransport.swift | 13 +++++++++++-- .../Test_AsyncHTTPClientTransport.swift | 10 +--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 748c093..08d11b2 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -68,15 +68,24 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// The HTTP client used for performing HTTP calls. public var client: HTTPClient + /// The default shared HTTP client. + /// + /// This is a workaround for the lack of a shared client + /// in AsyncHTTPClient. Do not use this value directly, outside of + /// the `Configuration.init(client:timeout:)` initializer, as it will + /// likely be removed in the future. + private static let sharedClient: HTTPClient = .init() + /// The default request timeout. public var timeout: TimeAmount /// Creates a new configuration with the specified client and timeout. /// - Parameters: /// - client: The underlying client used to perform HTTP operations. + /// Provide nil to use the shared internal client. /// - timeout: The request timeout, defaults to 1 minute. - public init(client: HTTPClient = .init(), timeout: TimeAmount = .minutes(1)) { - self.client = client + public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) { + self.client = client ?? Self.sharedClient self.timeout = timeout } } diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index 03b732b..594a828 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -82,16 +82,8 @@ class Test_AsyncHTTPClientTransport: XCTestCase { } func testSend() async throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) - let httpClient = HTTPClient( - eventLoopGroupProvider: .shared(eventLoopGroup), - configuration: .init() - ) - defer { - try! httpClient.syncShutdown() - } let transport = AsyncHTTPClientTransport( - configuration: .init(client: httpClient), + configuration: .init(), requestSender: TestSender.test ) let request: OpenAPIRuntime.Request = .init( From 0a0c648c90b59dd8be59726ecc3a8c11d1e231ef Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 27 Sep 2023 17:58:10 +0200 Subject: [PATCH 12/40] [AHC Transport] Async bodies + swift-http-types adoption (#16) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [AHC Transport] Async bodies + swift-http-types adoption ### Motivation AHC transport changes of the approved proposals apple/swift-openapi-generator#255 and apple/swift-openapi-generator#254. ### Modifications - Adapts to the runtime changes, depends on HTTPTypes now. - Both request and response streaming works. ### Result Transport works with the 0.3.0 runtime API of. ### Test Plan Adapted tests. Reviewed by: dnadoba, simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/16 --- Package.swift | 2 +- README.md | 2 +- .../AsyncHTTPClientTransport.swift | 93 +++++++++++++------ .../Documentation.docc/Documentation.md | 2 +- .../Test_AsyncHTTPClientTransport.swift | 44 ++++++--- 5 files changed, 99 insertions(+), 44 deletions(-) diff --git a/Package.swift b/Package.swift index b7d99bb..2c1c322 100644 --- a/Package.swift +++ b/Package.swift @@ -40,7 +40,7 @@ let package = Package( dependencies: [ .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", "0.1.3" ..< "0.3.0"), + .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.0")), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], targets: [ diff --git a/README.md b/README.md index b9d442c..666c32b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add the package dependency in your `Package.swift`: ```swift .package( url: "https://github.com/swift-server/swift-openapi-async-http-client", - .upToNextMinor(from: "0.2.0") + .upToNextMinor(from: "0.3.0") ), ``` diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 08d11b2..26efd0d 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -16,6 +16,7 @@ import AsyncHTTPClient import NIOCore import NIOHTTP1 import NIOFoundationCompat +import HTTPTypes #if canImport(Darwin) import Foundation #else @@ -100,7 +101,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { internal enum Error: Swift.Error, CustomStringConvertible, LocalizedError { /// Invalid URL composed from base URL and received request. - case invalidRequestURL(request: OpenAPIRuntime.Request, baseURL: URL) + case invalidRequestURL(request: HTTPRequest, baseURL: URL) // MARK: CustomStringConvertible @@ -108,7 +109,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { switch self { case let .invalidRequestURL(request: request, baseURL: baseURL): return - "Invalid request URL from request path: \(request.path), query: \(request.query ?? "") relative to base URL: \(baseURL.absoluteString)" + "Invalid request URL from request path: \(request.path ?? "") relative to base URL: \(baseURL.absoluteString)" } } @@ -150,13 +151,17 @@ public struct AsyncHTTPClientTransport: ClientTransport { // MARK: ClientTransport public func send( - _ request: OpenAPIRuntime.Request, + _ request: HTTPRequest, + body: HTTPBody?, baseURL: URL, operationID: String - ) async throws -> OpenAPIRuntime.Response { - let httpRequest = try Self.convertRequest(request, baseURL: baseURL) + ) async throws -> (HTTPResponse, HTTPBody?) { + let httpRequest = try Self.convertRequest(request, body: body, baseURL: baseURL) let httpResponse = try await invokeSession(with: httpRequest) - let response = try await Self.convertResponse(httpResponse) + let response = try await Self.convertResponse( + method: request.method, + httpResponse: httpResponse + ) return response } @@ -164,43 +169,79 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// Converts the shared Request type into URLRequest. internal static func convertRequest( - _ request: OpenAPIRuntime.Request, + _ request: HTTPRequest, + body: HTTPBody?, baseURL: URL ) throws -> HTTPClientRequest { - guard var baseUrlComponents = URLComponents(string: baseURL.absoluteString) else { + guard + var baseUrlComponents = URLComponents(string: baseURL.absoluteString), + let requestUrlComponents = URLComponents(string: request.path ?? "") + else { throw Error.invalidRequestURL(request: request, baseURL: baseURL) } - baseUrlComponents.percentEncodedPath += request.path - baseUrlComponents.percentEncodedQuery = request.query + baseUrlComponents.percentEncodedPath += requestUrlComponents.percentEncodedPath + baseUrlComponents.percentEncodedQuery = requestUrlComponents.percentEncodedQuery guard let url = baseUrlComponents.url else { throw Error.invalidRequestURL(request: request, baseURL: baseURL) } var clientRequest = HTTPClientRequest(url: url.absoluteString) clientRequest.method = request.method.asHTTPMethod for header in request.headerFields { - clientRequest.headers.add(name: header.name.lowercased(), value: header.value) + clientRequest.headers.add(name: header.name.canonicalName, value: header.value) } - if let body = request.body { - clientRequest.body = .bytes(body) + if let body { + let length: HTTPClientRequest.Body.Length + switch body.length { + case .unknown: + length = .unknown + case .known(let count): + length = .known(count) + } + clientRequest.body = .stream( + body.map { .init(bytes: $0) }, + length: length + ) } return clientRequest } /// Converts the received URLResponse into the shared Response. internal static func convertResponse( - _ httpResponse: HTTPClientResponse - ) async throws -> OpenAPIRuntime.Response { - let headerFields: [OpenAPIRuntime.HeaderField] = httpResponse - .headers - .map { .init(name: $0, value: $1) } - let body = try await httpResponse.body.collect(upTo: .max) - let bodyData = Data(buffer: body, byteTransferStrategy: .noCopy) - let response = OpenAPIRuntime.Response( - statusCode: Int(httpResponse.status.code), - headerFields: headerFields, - body: bodyData + method: HTTPRequest.Method, + httpResponse: HTTPClientResponse + ) async throws -> (HTTPResponse, HTTPBody?) { + + var headerFields: HTTPFields = [:] + for header in httpResponse.headers { + headerFields[.init(header.name)!] = header.value + } + + let length: HTTPBody.Length + if let lengthHeaderString = headerFields[.contentLength], + let lengthHeader = Int(lengthHeaderString) + { + length = .known(lengthHeader) + } else { + length = .unknown + } + + let body: HTTPBody? + switch method { + case .head, .connect, .trace: + body = nil + default: + body = HTTPBody( + httpResponse.body.map { $0.readableBytesView }, + length: length, + iterationBehavior: .single + ) + } + + let response = HTTPResponse( + status: .init(code: Int(httpResponse.status.code)), + headerFields: headerFields ) - return response + return (response, body) } // MARK: Private @@ -215,7 +256,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { } } -extension OpenAPIRuntime.HTTPMethod { +extension HTTPTypes.HTTPRequest.Method { var asHTTPMethod: NIOHTTP1.HTTPMethod { switch self { case .get: diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index 054a552..25d9032 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -20,7 +20,7 @@ Add the package dependency in your `Package.swift`: ```swift .package( url: "https://github.com/swift-server/swift-openapi-async-http-client", - .upToNextMinor(from: "0.2.0") + .upToNextMinor(from: "0.3.0") ), ``` diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index 594a828..e899261 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -17,6 +17,7 @@ import NIOCore import NIOPosix import AsyncHTTPClient @testable import OpenAPIAsyncHTTPClient +import HTTPTypes class Test_AsyncHTTPClientTransport: XCTestCase { @@ -37,17 +38,19 @@ class Test_AsyncHTTPClientTransport: XCTestCase { } func testConvertRequest() throws { - let request: OpenAPIRuntime.Request = .init( - path: "/hello%20world/Maria", - query: "greeting=Howdy", + let request: HTTPRequest = .init( method: .post, + scheme: nil, + authority: nil, + path: "/hello%20world/Maria?greeting=Howdy", headerFields: [ - .init(name: "content-type", value: "application/json") - ], - body: try Self.testData + .contentType: "application/json" + ] ) + let requestBody = try HTTPBody(Self.testData) let httpRequest = try AsyncHTTPClientTransport.convertRequest( request, + body: requestBody, baseURL: try XCTUnwrap(URL(string: "http://example.com/api/v1")) ) XCTAssertEqual(httpRequest.url, "http://example.com/api/v1/hello%20world/Maria?greeting=Howdy") @@ -70,15 +73,20 @@ class Test_AsyncHTTPClientTransport: XCTestCase { ], body: .bytes(Self.testBuffer) ) - let response = try await AsyncHTTPClientTransport.convertResponse(httpResponse) - XCTAssertEqual(response.statusCode, 200) + let (response, maybeResponseBody) = try await AsyncHTTPClientTransport.convertResponse( + method: .get, + httpResponse: httpResponse + ) + let responseBody = try XCTUnwrap(maybeResponseBody) + XCTAssertEqual(response.status.code, 200) XCTAssertEqual( response.headerFields, [ - .init(name: "content-type", value: "application/json") + .contentType: "application/json" ] ) - XCTAssertEqual(response.body, try Self.testData) + let bufferedResponseBody = try await Data(collecting: responseBody, upTo: .max) + XCTAssertEqual(bufferedResponseBody, try Self.testData) } func testSend() async throws { @@ -86,19 +94,25 @@ class Test_AsyncHTTPClientTransport: XCTestCase { configuration: .init(), requestSender: TestSender.test ) - let request: OpenAPIRuntime.Request = .init( - path: "/api/v1/hello/Maria", + let request: HTTPRequest = .init( method: .get, + scheme: nil, + authority: nil, + path: "/api/v1/hello/Maria", headerFields: [ - .init(name: "x-request", value: "yes") + .init("x-request")!: "yes" ] ) - let response = try await transport.send( + let (response, maybeResponseBody) = try await transport.send( request, + body: nil, baseURL: Self.testUrl, operationID: "sayHello" ) - XCTAssertEqual(response.statusCode, 200) + let responseBody = try XCTUnwrap(maybeResponseBody) + let bufferedResponseBody = try await String(collecting: responseBody, upTo: .max) + XCTAssertEqual(bufferedResponseBody, "[{}]") + XCTAssertEqual(response.status.code, 200) } } From 6779786e543573b0a37e6f309b77faedf1a73b57 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Wed, 4 Oct 2023 18:53:33 +0100 Subject: [PATCH 13/40] Add docker-compose file for 5.10 CI (#19) ### Motivation Now Swift 5.9 is released and 5.10 nightly images are available, we should update our CI to use the official release for 5.10 and setup a new CI for 5.10. ### Modifications - Update 5.9 CI to use `swift:5.9-jammy` - Add new CI for `swiftlang/swift:nightly-5.10-jammy` ### Result - 5.9 CI is using official released image. - 5.10 CI can be brought online. ### Test Plan Running both of these commands locally succeed: ```console % docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.2204.59.yaml run test ``` ```console % docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.2204.510.yaml run test ``` --- docker/docker-compose.2204.510.yaml | 17 +++++++++++++++++ docker/docker-compose.2204.59.yaml | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 docker/docker-compose.2204.510.yaml diff --git a/docker/docker-compose.2204.510.yaml b/docker/docker-compose.2204.510.yaml new file mode 100644 index 0000000..20a4467 --- /dev/null +++ b/docker/docker-compose.2204.510.yaml @@ -0,0 +1,17 @@ +version: "3" + +services: + runtime-setup: + image: &image swift-openapi-ahc:22.04-5.10 + build: + args: + base_image: "swiftlang/swift:nightly-5.10-jammy" + + test: + image: *image + environment: + - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors + - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + + shell: + image: *image diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml index 1ac8741..75b3e5a 100644 --- a/docker/docker-compose.2204.59.yaml +++ b/docker/docker-compose.2204.59.yaml @@ -5,7 +5,8 @@ services: image: &image swift-openapi-ahc:22.04-5.9 build: args: - base_image: "swiftlang/swift:nightly-5.9-jammy" + ubuntu_version: "jammy" + swift_version: "5.9" test: image: *image From f3fa4a50085ded2b03cca5ce3622d3ada04efd46 Mon Sep 17 00:00:00 2001 From: PARAIPAN SORIN <51127880+PARAIPAN9@users.noreply.github.com> Date: Tue, 24 Oct 2023 00:05:38 +0300 Subject: [PATCH 14/40] Enable documentation comment validation in swift-format (#21) --- .swift-format | 4 ++-- .../AsyncHTTPClientTransport.swift | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.swift-format b/.swift-format index e6a70ed..f8c8ff5 100644 --- a/.swift-format +++ b/.swift-format @@ -16,7 +16,7 @@ "prioritizeKeepingFunctionOutputTogether" : false, "respectsExistingLineBreaks" : true, "rules" : { - "AllPublicDeclarationsHaveDocumentation" : false, + "AllPublicDeclarationsHaveDocumentation" : true, "AlwaysUseLowerCamelCase" : false, "AmbiguousTrailingClosureOverload" : true, "BeginDocumentationCommentWithOneLineSummary" : false, @@ -50,7 +50,7 @@ "UseSynthesizedInitializer" : true, "UseTripleSlashForDocumentationComments" : true, "UseWhereClausesInForLoops" : false, - "ValidateDocumentationComments" : false + "ValidateDocumentationComments" : true }, "spacesAroundRangeFormationOperators" : false, "tabWidth" : 8, diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 26efd0d..bb68295 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -139,8 +139,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { } /// Creates a new transport. - /// - Parameters: - /// - configuration: A set of configuration values used by the transport. + /// - Parameter configuration: A set of configuration values used by the transport. public init(configuration: Configuration) { self.init( configuration: configuration, @@ -150,6 +149,16 @@ public struct AsyncHTTPClientTransport: ClientTransport { // MARK: ClientTransport + /// Sends an HTTP request and returns the corresponding HTTP response. + /// + /// - Parameters: + /// - request: The HTTP request to send. + /// - body: The HTTP body to include in the request (optional). + /// - baseURL: The base URL for the request. + /// - operationID: The identifier for the operation. + /// + /// - Returns: A tuple containing the HTTP response and an optional HTTP body in the response. + /// - Throws: An error if the request or response handling encounters any issues. public func send( _ request: HTTPRequest, body: HTTPBody?, From 2e72905ccc51cb43fe341abe4cc0e85105e5be06 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 24 Oct 2023 08:50:44 +0200 Subject: [PATCH 15/40] Bump swift-format to 5.9 (#20) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bump swift-format to 5.9 ### Motivation As per https://github.com/apple/swift-openapi-generator/issues/175. ### Modifications Bump swift-format, update to make soundness pass. ### Result Using swift-format 5.9. ### Test Plan Soundness passed. Reviewed by: dnadoba Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/20 --- .../Test_AsyncHTTPClientTransport.swift | 4 ++-- docker/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index e899261..4a627a4 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -118,8 +118,8 @@ class Test_AsyncHTTPClientTransport: XCTestCase { struct TestSender: HTTPRequestSending { var sendClosure: - @Sendable (AsyncHTTPClientTransport.Request, HTTPClient, TimeAmount) async throws -> AsyncHTTPClientTransport - .Response + @Sendable (AsyncHTTPClientTransport.Request, HTTPClient, TimeAmount) async throws -> + AsyncHTTPClientTransport.Response func send( request: AsyncHTTPClientTransport.Request, with client: HTTPClient, diff --git a/docker/Dockerfile b/docker/Dockerfile index 4b7014a..3cc66ea 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -17,7 +17,7 @@ RUN mkdir -p $HOME/.tools RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile # swift-format -ARG swiftformat_version=508.0.0 +ARG swiftformat_version=509.0.0 RUN git clone --branch $swiftformat_version --depth 1 https://github.com/apple/swift-format $HOME/.tools/swift-format-source RUN cd $HOME/.tools/swift-format-source && swift build -c release -RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format \ No newline at end of file +RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format From 7c6a9e73040cfb3555bbae9c1a8380e35c834a40 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 12:01:10 +0200 Subject: [PATCH 16/40] Add a soundness --fix flag (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a soundness --fix flag ### Motivation When running `./scripts/soundness.sh` produces swift-format warnings, we ask adopters to manually copy/paste a call to swift format to fix the warnings up. This is tedious and unnecessary. ### Modifications Add a `--fix` option on the `soundness.sh` script to actually apply the fixes as well, avoiding the need to copy/paste long commands. ### Result Easier fixing up of formatting warnings. ### Test Plan Manually tested the workflow locally. Reviewed by: glbrntt Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/22 --- scripts/run-swift-format.sh | 13 ++++++++++--- scripts/soundness.sh | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) mode change 100644 => 100755 scripts/run-swift-format.sh diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh old mode 100644 new mode 100755 index e2011cf..eefa585 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -21,10 +21,17 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" +FORMAT_COMMAND=(lint --strict) +for arg in "$@"; do + if [ "$arg" == "--fix" ]; then + FORMAT_COMMAND=(format --in-place) + fi +done + SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" -"${SWIFTFORMAT_BIN}" lint \ - --parallel --recursive --strict \ +"${SWIFTFORMAT_BIN}" "${FORMAT_COMMAND[@]}" \ + --parallel --recursive \ "${REPO_ROOT}/Sources" "${REPO_ROOT}/Tests" \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? @@ -33,7 +40,7 @@ if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then To fix, run the following command: - % swift-format format --parallel --recursive --in-place Sources Tests + % ./scripts/run-swift-format.sh --fix " exit "${SWIFT_FORMAT_RC}" fi diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 1baf17f..7543915 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -22,11 +22,17 @@ CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" NUM_CHECKS_FAILED=0 export DOCC_TARGET=OpenAPIAsyncHTTPClient +FIX_FORMAT="" +for arg in "$@"; do + if [ "$arg" == "--fix" ]; then + FIX_FORMAT="--fix" + fi +done + SCRIPT_PATHS=( "${CURRENT_SCRIPT_DIR}/check-for-broken-symlinks.sh" "${CURRENT_SCRIPT_DIR}/check-for-unacceptable-language.sh" "${CURRENT_SCRIPT_DIR}/check-license-headers.sh" - "${CURRENT_SCRIPT_DIR}/run-swift-format.sh" "${CURRENT_SCRIPT_DIR}/check-for-docc-warnings.sh" ) @@ -37,6 +43,13 @@ for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do fi done +log "Running swift-format..." +bash "${CURRENT_SCRIPT_DIR}"/run-swift-format.sh $FIX_FORMAT > /dev/null +FORMAT_EXIT_CODE=$? +if [ $FORMAT_EXIT_CODE -ne 0 ]; then + ((NUM_CHECKS_FAILED+=1)) +fi + if [ "${NUM_CHECKS_FAILED}" -gt 0 ]; then fatal "❌ ${NUM_CHECKS_FAILED} soundness check(s) failed." fi From e48b152d18895ea9f013945bf952ff37e57a3117 Mon Sep 17 00:00:00 2001 From: PARAIPAN SORIN <51127880+PARAIPAN9@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:49:29 +0200 Subject: [PATCH 17/40] Disable "respectsExistingLineBreaks" in .swift-format for more consistent styling (#23) ### Motivation - Relates to [#230](https://github.com/apple/swift-openapi-generator/issues/230) ### Modifications - Disable respectsExistingLineBreaks .swift-format rule and address changes requested ### Result - One of the .swift-format rules will be disabled ### Test Plan - Run Tests --- .swift-format | 2 +- .../AsyncHTTPClientTransport.swift | 140 +++++------------- .../Test_AsyncHTTPClientTransport.swift | 59 ++------ 3 files changed, 53 insertions(+), 148 deletions(-) diff --git a/.swift-format b/.swift-format index f8c8ff5..0df000c 100644 --- a/.swift-format +++ b/.swift-format @@ -14,7 +14,7 @@ "lineLength" : 120, "maximumBlankLines" : 1, "prioritizeKeepingFunctionOutputTogether" : false, - "respectsExistingLineBreaks" : true, + "respectsExistingLineBreaks" : false, "rules" : { "AllPublicDeclarationsHaveDocumentation" : true, "AlwaysUseLowerCamelCase" : false, diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index bb68295..5851103 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -115,9 +115,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { // MARK: LocalizedError - var errorDescription: String? { - description - } + var errorDescription: String? { description } } /// A set of configuration values used by the transport. @@ -130,10 +128,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// - Parameters: /// - configuration: A set of configuration values used by the transport. /// - requestSender: The underlying request sender. - internal init( - configuration: Configuration, - requestSender: any HTTPRequestSending - ) { + internal init(configuration: Configuration, requestSender: any HTTPRequestSending) { self.configuration = configuration self.requestSender = requestSender } @@ -141,10 +136,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// Creates a new transport. /// - Parameter configuration: A set of configuration values used by the transport. public init(configuration: Configuration) { - self.init( - configuration: configuration, - requestSender: AsyncHTTPRequestSender() - ) + self.init(configuration: configuration, requestSender: AsyncHTTPRequestSender()) } // MARK: ClientTransport @@ -159,40 +151,27 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// /// - Returns: A tuple containing the HTTP response and an optional HTTP body in the response. /// - Throws: An error if the request or response handling encounters any issues. - public func send( - _ request: HTTPRequest, - body: HTTPBody?, - baseURL: URL, - operationID: String - ) async throws -> (HTTPResponse, HTTPBody?) { + public func send(_ request: HTTPRequest, body: HTTPBody?, baseURL: URL, operationID: String) async throws -> ( + HTTPResponse, HTTPBody? + ) { let httpRequest = try Self.convertRequest(request, body: body, baseURL: baseURL) let httpResponse = try await invokeSession(with: httpRequest) - let response = try await Self.convertResponse( - method: request.method, - httpResponse: httpResponse - ) + let response = try await Self.convertResponse(method: request.method, httpResponse: httpResponse) return response } // MARK: Internal /// Converts the shared Request type into URLRequest. - internal static func convertRequest( - _ request: HTTPRequest, - body: HTTPBody?, - baseURL: URL - ) throws -> HTTPClientRequest { - guard - var baseUrlComponents = URLComponents(string: baseURL.absoluteString), + internal static func convertRequest(_ request: HTTPRequest, body: HTTPBody?, baseURL: URL) throws + -> HTTPClientRequest + { + guard var baseUrlComponents = URLComponents(string: baseURL.absoluteString), let requestUrlComponents = URLComponents(string: request.path ?? "") - else { - throw Error.invalidRequestURL(request: request, baseURL: baseURL) - } + else { throw Error.invalidRequestURL(request: request, baseURL: baseURL) } baseUrlComponents.percentEncodedPath += requestUrlComponents.percentEncodedPath baseUrlComponents.percentEncodedQuery = requestUrlComponents.percentEncodedQuery - guard let url = baseUrlComponents.url else { - throw Error.invalidRequestURL(request: request, baseURL: baseURL) - } + guard let url = baseUrlComponents.url else { throw Error.invalidRequestURL(request: request, baseURL: baseURL) } var clientRequest = HTTPClientRequest(url: url.absoluteString) clientRequest.method = request.method.asHTTPMethod for header in request.headerFields { @@ -201,34 +180,24 @@ public struct AsyncHTTPClientTransport: ClientTransport { if let body { let length: HTTPClientRequest.Body.Length switch body.length { - case .unknown: - length = .unknown - case .known(let count): - length = .known(count) + case .unknown: length = .unknown + case .known(let count): length = .known(count) } - clientRequest.body = .stream( - body.map { .init(bytes: $0) }, - length: length - ) + clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length) } return clientRequest } /// Converts the received URLResponse into the shared Response. - internal static func convertResponse( - method: HTTPRequest.Method, - httpResponse: HTTPClientResponse - ) async throws -> (HTTPResponse, HTTPBody?) { + internal static func convertResponse(method: HTTPRequest.Method, httpResponse: HTTPClientResponse) async throws -> ( + HTTPResponse, HTTPBody? + ) { var headerFields: HTTPFields = [:] - for header in httpResponse.headers { - headerFields[.init(header.name)!] = header.value - } + for header in httpResponse.headers { headerFields[.init(header.name)!] = header.value } let length: HTTPBody.Length - if let lengthHeaderString = headerFields[.contentLength], - let lengthHeader = Int(lengthHeaderString) - { + if let lengthHeaderString = headerFields[.contentLength], let lengthHeader = Int(lengthHeaderString) { length = .known(lengthHeader) } else { length = .unknown @@ -236,20 +205,12 @@ public struct AsyncHTTPClientTransport: ClientTransport { let body: HTTPBody? switch method { - case .head, .connect, .trace: - body = nil + case .head, .connect, .trace: body = nil default: - body = HTTPBody( - httpResponse.body.map { $0.readableBytesView }, - length: length, - iterationBehavior: .single - ) + body = HTTPBody(httpResponse.body.map { $0.readableBytesView }, length: length, iterationBehavior: .single) } - let response = HTTPResponse( - status: .init(code: Int(httpResponse.status.code)), - headerFields: headerFields - ) + let response = HTTPResponse(status: .init(code: Int(httpResponse.status.code)), headerFields: headerFields) return (response, body) } @@ -257,58 +218,35 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// Makes the underlying HTTP call. private func invokeSession(with request: Request) async throws -> Response { - try await requestSender.send( - request: request, - with: configuration.client, - timeout: configuration.timeout - ) + try await requestSender.send(request: request, with: configuration.client, timeout: configuration.timeout) } } extension HTTPTypes.HTTPRequest.Method { var asHTTPMethod: NIOHTTP1.HTTPMethod { switch self { - case .get: - return .GET - case .put: - return .PUT - case .post: - return .POST - case .delete: - return .DELETE - case .options: - return .OPTIONS - case .head: - return .HEAD - case .patch: - return .PATCH - case .trace: - return .TRACE - default: - return .RAW(value: rawValue) + case .get: return .GET + case .put: return .PUT + case .post: return .POST + case .delete: return .DELETE + case .options: return .OPTIONS + case .head: return .HEAD + case .patch: return .PATCH + case .trace: return .TRACE + default: return .RAW(value: rawValue) } } } /// A type that performs HTTP operations using the HTTP client. internal protocol HTTPRequestSending: Sendable { - func send( - request: AsyncHTTPClientTransport.Request, - with client: HTTPClient, - timeout: TimeAmount - ) async throws -> AsyncHTTPClientTransport.Response + func send(request: AsyncHTTPClientTransport.Request, with client: HTTPClient, timeout: TimeAmount) async throws + -> AsyncHTTPClientTransport.Response } /// Performs HTTP calls using AsyncHTTPClient internal struct AsyncHTTPRequestSender: HTTPRequestSending { - func send( - request: AsyncHTTPClientTransport.Request, - with client: AsyncHTTPClient.HTTPClient, - timeout: TimeAmount - ) async throws -> AsyncHTTPClientTransport.Response { - try await client.execute( - request, - timeout: timeout - ) - } + func send(request: AsyncHTTPClientTransport.Request, with client: AsyncHTTPClient.HTTPClient, timeout: TimeAmount) + async throws -> AsyncHTTPClientTransport.Response + { try await client.execute(request, timeout: timeout) } } diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index 4a627a4..7bd9f41 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -21,20 +21,12 @@ import HTTPTypes class Test_AsyncHTTPClientTransport: XCTestCase { - static var testData: Data { - get throws { - try XCTUnwrap(#"[{}]"#.data(using: .utf8)) - } - } + static var testData: Data { get throws { try XCTUnwrap(#"[{}]"#.data(using: .utf8)) } } - static var testBuffer: ByteBuffer { - ByteBuffer(string: #"[{}]"#) - } + static var testBuffer: ByteBuffer { ByteBuffer(string: #"[{}]"#) } static var testUrl: URL { - get throws { - try XCTUnwrap(URL(string: "http://example.com/api/v1/hello/Maria?greeting=Howdy")) - } + get throws { try XCTUnwrap(URL(string: "http://example.com/api/v1/hello/Maria?greeting=Howdy")) } } func testConvertRequest() throws { @@ -43,9 +35,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { scheme: nil, authority: nil, path: "/hello%20world/Maria?greeting=Howdy", - headerFields: [ - .contentType: "application/json" - ] + headerFields: [.contentType: "application/json"] ) let requestBody = try HTTPBody(Self.testData) let httpRequest = try AsyncHTTPClientTransport.convertRequest( @@ -55,12 +45,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { ) XCTAssertEqual(httpRequest.url, "http://example.com/api/v1/hello%20world/Maria?greeting=Howdy") XCTAssertEqual(httpRequest.method, .POST) - XCTAssertEqual( - httpRequest.headers, - [ - "content-type": "application/json" - ] - ) + XCTAssertEqual(httpRequest.headers, ["content-type": "application/json"]) // TODO: Not sure how to test that httpRequest.body is what we expect, can't // find an API for reading it back. } @@ -68,9 +53,7 @@ class Test_AsyncHTTPClientTransport: XCTestCase { func testConvertResponse() async throws { let httpResponse = HTTPClientResponse( status: .ok, - headers: [ - "content-type": "application/json" - ], + headers: ["content-type": "application/json"], body: .bytes(Self.testBuffer) ) let (response, maybeResponseBody) = try await AsyncHTTPClientTransport.convertResponse( @@ -79,29 +62,19 @@ class Test_AsyncHTTPClientTransport: XCTestCase { ) let responseBody = try XCTUnwrap(maybeResponseBody) XCTAssertEqual(response.status.code, 200) - XCTAssertEqual( - response.headerFields, - [ - .contentType: "application/json" - ] - ) + XCTAssertEqual(response.headerFields, [.contentType: "application/json"]) let bufferedResponseBody = try await Data(collecting: responseBody, upTo: .max) XCTAssertEqual(bufferedResponseBody, try Self.testData) } func testSend() async throws { - let transport = AsyncHTTPClientTransport( - configuration: .init(), - requestSender: TestSender.test - ) + let transport = AsyncHTTPClientTransport(configuration: .init(), requestSender: TestSender.test) let request: HTTPRequest = .init( method: .get, scheme: nil, authority: nil, path: "/api/v1/hello/Maria", - headerFields: [ - .init("x-request")!: "yes" - ] + headerFields: [.init("x-request")!: "yes"] ) let (response, maybeResponseBody) = try await transport.send( request, @@ -120,22 +93,16 @@ struct TestSender: HTTPRequestSending { var sendClosure: @Sendable (AsyncHTTPClientTransport.Request, HTTPClient, TimeAmount) async throws -> AsyncHTTPClientTransport.Response - func send( - request: AsyncHTTPClientTransport.Request, - with client: HTTPClient, - timeout: TimeAmount - ) async throws -> AsyncHTTPClientTransport.Response { - try await sendClosure(request, client, timeout) - } + func send(request: AsyncHTTPClientTransport.Request, with client: HTTPClient, timeout: TimeAmount) async throws + -> AsyncHTTPClientTransport.Response + { try await sendClosure(request, client, timeout) } static var test: Self { TestSender { request, _, _ in XCTAssertEqual(request.headers.first(name: "x-request"), "yes") return HTTPClientResponse( status: .ok, - headers: [ - "content-type": "application/json" - ], + headers: ["content-type": "application/json"], body: .bytes(Test_AsyncHTTPClientTransport.testBuffer) ) } From 701d752f2512acf4e27f1d6d3f771b5bdf0f82cb Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 16 Nov 2023 08:47:28 +0100 Subject: [PATCH 18/40] Add README badges (#24) ### Motivation Surface the Swift version and platform support status from Swift Package Index. ### Modifications Added badges, plus a quick link to the docc docs, to the top of the README. Also, expanded the supported platforms, we do actually support iOS and friends (was an oversight not to include it before). ### Result Easier to quickly see our support matrix, plus the quick link to docs. ### Test Plan Previewed locally. --- Package.swift | 2 +- README.md | 12 ++++++++---- .../Documentation.docc/Documentation.md | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index 2c1c322..b6af358 100644 --- a/Package.swift +++ b/Package.swift @@ -29,7 +29,7 @@ swiftSettings.append( let package = Package( name: "swift-openapi-async-http-client", platforms: [ - .macOS(.v10_15), + .macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), ], products: [ .library( diff --git a/README.md b/README.md index 666c32b..30e5981 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,17 @@ # AsyncHTTPClient Transport for Swift OpenAPI Generator -A client transport that uses the [HTTPClient](https://swift-server.github.io/async-http-client/docs/current/AsyncHTTPClient/Classes/HTTPClient) type from the [AsyncHTTPClient](https://github.com/swift-server/async-http-client) library to perform HTTP operations. +[![](https://img.shields.io/badge/docc-read_documentation-blue)](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client/documentation) +[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswift-server%2Fswift-openapi-async-http-client%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client) +[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswift-server%2Fswift-openapi-async-http-client%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client) + +A client transport that uses the [HTTPClient](https://swiftpackageindex.com/swift-server/async-http-client/documentation/asynchttpclient/httpclient) type from the [AsyncHTTPClient](https://github.com/swift-server/async-http-client) library to perform HTTP operations. Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). ## Supported platforms and minimum versions - | macOS | Linux | - | :-: | :-: | - | ✅ 10.15+ | ✅ | +| macOS | Linux | iOS | tvOS | watchOS | +| :-: | :-: | :-: | :-: | :-: | +| ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | ## Usage diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index 25d9032..a70975d 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -4,14 +4,14 @@ Send HTTP requests to the server using the AsyncHTTPClient library. ## Overview -A client transport that uses the [HTTPClient](https://swift-server.github.io/async-http-client/docs/current/AsyncHTTPClient/Classes/HTTPClient) type from the [AsyncHTTPClient](https://github.com/swift-server/async-http-client) library to perform HTTP operations. +A client transport that uses the [HTTPClient](https://swiftpackageindex.com/swift-server/async-http-client/documentation/asynchttpclient/httpclient) type from the [AsyncHTTPClient](https://github.com/swift-server/async-http-client) library to perform HTTP operations. Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). ### Supported platforms and minimum versions -| macOS | Linux | -| :-: | :-: | -| ✅ 10.15+ | ✅ | +| macOS | Linux | iOS | tvOS | watchOS | +| :-: | :-: | :-: | :-: | :-: | +| ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | ### Usage From caa53033fe796670a3a466a4778a46cb7d33df77 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 27 Nov 2023 16:13:23 +0100 Subject: [PATCH 19/40] Prep for 1.0 alpha, adapted to runtime changes in main (#25) ### Motivation On main, the HTTPBody length type changed from Int to Int64. ### Modifications Adapted the transport with this change. ### Result Repo builds again when using the latest runtime. ### Test Plan Adapted tests. --- Package.swift | 2 +- Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index b6af358..d647d93 100644 --- a/Package.swift +++ b/Package.swift @@ -40,7 +40,7 @@ let package = Package( dependencies: [ .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.3.0")), + .package(url: "https://github.com/apple/swift-openapi-runtime", branch: "main"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], targets: [ diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 5851103..2ed27c2 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -181,7 +181,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { let length: HTTPClientRequest.Body.Length switch body.length { case .unknown: length = .unknown - case .known(let count): length = .known(count) + case .known(let count): length = .known(Int(count)) } clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length) } @@ -197,7 +197,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { for header in httpResponse.headers { headerFields[.init(header.name)!] = header.value } let length: HTTPBody.Length - if let lengthHeaderString = headerFields[.contentLength], let lengthHeader = Int(lengthHeaderString) { + if let lengthHeaderString = headerFields[.contentLength], let lengthHeader = Int64(lengthHeaderString) { length = .known(lengthHeader) } else { length = .unknown From 8c6cc5907c5299a3358dc0dac8e48102e2f61038 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 27 Nov 2023 16:19:22 +0100 Subject: [PATCH 20/40] Move to Swift 5.9 as the minimum version (#26) ### Motivation Part of addressing https://github.com/apple/swift-openapi-generator/issues/75 and https://github.com/apple/swift-openapi-generator/issues/119. ### Modifications Bumped Swift tools version to 5.9 and made the `ExistentialAny` build setting unconditional. ### Result Building the package requires 5.9 now. ### Test Plan Ran tests, all passed when using a Swift 5.9 toolchain. --- Package.swift | 2 +- docker/Dockerfile | 2 +- docker/docker-compose.2204.58.yaml | 19 ------------------- docker/docker-compose.yaml | 2 +- 4 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 docker/docker-compose.2204.58.yaml diff --git a/Package.swift b/Package.swift index d647d93..86bffb5 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.8 +// swift-tools-version: 5.9 //===----------------------------------------------------------------------===// // // This source file is part of the SwiftOpenAPIGenerator open source project diff --git a/docker/Dockerfile b/docker/Dockerfile index 3cc66ea..d90e973 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -ARG swift_version=5.8 +ARG swift_version=5.9 ARG ubuntu_version=jammy ARG base_image=swift:${swift_version}-${ubuntu_version} diff --git a/docker/docker-compose.2204.58.yaml b/docker/docker-compose.2204.58.yaml deleted file mode 100644 index eca0761..0000000 --- a/docker/docker-compose.2204.58.yaml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-ahc:22.04-5.8 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.8" - - test: - image: *image - 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 055978f..0921dad 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -4,7 +4,7 @@ # # % docker-compose \ # -f docker/docker-compose.yaml \ -# -f docker/docker-compose.2204.58.yaml \ +# -f docker/docker-compose.2204.59.yaml \ # run test # version: "3" From e0c24bc0b9de1d5513c7c13d61f281cc517a80fd Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Mon, 27 Nov 2023 16:35:03 +0000 Subject: [PATCH 21/40] Remove #if swift(>=5.9) check in Package.swift (#27) ### Motivation In #26 we bumped the minimum tools version to Swift 5.9, but we left the `#if swift(>5.9)` compiler directive when enabling existential any by default. ### Modifications Remove #if swift(>=5.9) check in Package.swift ### Result No checking for Swift 5.9+, because that's now the default. ### Test Plan CI. --- Package.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 86bffb5..9c3efdc 100644 --- a/Package.swift +++ b/Package.swift @@ -16,15 +16,11 @@ import Foundation import PackageDescription // General Swift-settings for all targets. -var swiftSettings: [SwiftSetting] = [] - -#if swift(>=5.9) -swiftSettings.append( +let swiftSettings: [SwiftSetting] = [ // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md // Require `any` for existential types. .enableUpcomingFeature("ExistentialAny") -) -#endif +] let package = Package( name: "swift-openapi-async-http-client", From f5bf294257a3183804ba64fa28c5322431adc6e0 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 28 Nov 2023 10:40:48 +0100 Subject: [PATCH 22/40] Bump to 1.0.0-alpha.1 (#28) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bump to 1.0.0-alpha.1 ### Motivation Prepare for 1.0.0-alpha.1. ### Modifications - Updated runtime dependency. - Updated docs. ### Result Ready to tag 1.0.0-alpha.1. ### Test Plan All tests pass. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/28 --- Package.swift | 2 +- README.md | 2 +- .../OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 9c3efdc..6d83659 100644 --- a/Package.swift +++ b/Package.swift @@ -36,7 +36,7 @@ let package = Package( dependencies: [ .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", branch: "main"), + .package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], targets: [ diff --git a/README.md b/README.md index 30e5981..fde930f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Add the package dependency in your `Package.swift`: ```swift .package( url: "https://github.com/swift-server/swift-openapi-async-http-client", - .upToNextMinor(from: "0.3.0") + exact: "1.0.0-alpha.1" ), ``` diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index a70975d..123bc69 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -20,7 +20,7 @@ Add the package dependency in your `Package.swift`: ```swift .package( url: "https://github.com/swift-server/swift-openapi-async-http-client", - .upToNextMinor(from: "0.3.0") + exact: "1.0.0-alpha.1" ), ``` From 0859eada6f622262a61efe5667b0767725a4c786 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 28 Nov 2023 11:26:01 +0100 Subject: [PATCH 23/40] Handle large payloads on 32bit platforms gracefully (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handle large payloads on 32bit platforms gracefully ### Motivation If there's a request payload with a number of bytes that can't fit into 32 bits, we'd crash. ### Modifications Use a graceful initializer and use `.unknown` (so no `content-length` will be sent) if the size exceeds the max of a 32bit int. ### Result No crash for large payloads on 32bit platforms. ### Test Plan Tests pass. Reviewed by: dnadoba Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/29 --- Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 2ed27c2..6694a42 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -181,7 +181,8 @@ public struct AsyncHTTPClientTransport: ClientTransport { let length: HTTPClientRequest.Body.Length switch body.length { case .unknown: length = .unknown - case .known(let count): length = .known(Int(count)) + case .known(let count): + if let intValue = Int(exactly: count) { length = .known(intValue) } else { length = .unknown } } clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length) } From 1ab51feec5059b2bcd44488ba7aa706663051021 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 30 Nov 2023 09:51:18 +0100 Subject: [PATCH 24/40] Add visionOS platform support (#31) ### Motivation While this isn't technically necessary, as all versions of a platform not explicitly mentioned are assumed to be supported, it's better to be explicit here. ### Modifications Add `visionOS(.v1)` to the list of supported platforms. ### Result Clearer support matrix. ### Test Plan N/A, this is basically just a documentation change. --- Package.swift | 2 +- README.md | 6 +++--- .../Documentation.docc/Documentation.md | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index 6d83659..70b999c 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,7 @@ let swiftSettings: [SwiftSetting] = [ let package = Package( name: "swift-openapi-async-http-client", platforms: [ - .macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), + .macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1) ], products: [ .library( diff --git a/README.md b/README.md index fde930f..140a9f1 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ A client transport that uses the [HTTPClient](https://swiftpackageindex.com/swif Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). ## Supported platforms and minimum versions -| macOS | Linux | iOS | tvOS | watchOS | -| :-: | :-: | :-: | :-: | :-: | -| ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | +| macOS | Linux | iOS | tvOS | watchOS | visionOS | +| :-: | :-: | :-: | :-: | :-: | :-: | +| ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | ✅ 1+ | ## Usage diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index 123bc69..f41c431 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -9,9 +9,9 @@ A client transport that uses the [HTTPClient](https://swiftpackageindex.com/swif Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). ### Supported platforms and minimum versions -| macOS | Linux | iOS | tvOS | watchOS | -| :-: | :-: | :-: | :-: | :-: | -| ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | +| macOS | Linux | iOS | tvOS | watchOS | visionOS | +| :-: | :-: | :-: | :-: | :-: | :-: | +| ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | ✅ 1+ | ### Usage From 7edc42113fa9542ba36a827ba493727c2ff948d1 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 30 Nov 2023 13:39:25 +0100 Subject: [PATCH 25/40] Default the configuration parameter (#32) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default the configuration parameter ### Motivation The AsyncHTTPClient transport API has undergone changes in recent months and we didn't bring back the default initializer after we adopted the shared EventLoopGroup, allowing you to create a transport with just `let transport = AsyncHTTPClientTransport()`. ### Modifications Default the configuration parameter in the initializer to be able to do that. It's already documented to work, but it doesn't. ### Result Match the documented behavior of being able to use `let transport = AsyncHTTPClientTransport()`. ### Test Plan Tests still pass. Reviewed by: dnadoba Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. https://github.com/swift-server/swift-openapi-async-http-client/pull/32 --- Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index 6694a42..a43a074 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -135,7 +135,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// Creates a new transport. /// - Parameter configuration: A set of configuration values used by the transport. - public init(configuration: Configuration) { + public init(configuration: Configuration = .init()) { self.init(configuration: configuration, requestSender: AsyncHTTPRequestSender()) } From ddc356e9e19fa2608adaaea9dbdf98d70c0e7c3e Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Thu, 30 Nov 2023 20:26:33 +0000 Subject: [PATCH 26/40] Add Docker Compose file for Swift 5.9.0 (#33) --- docker/docker-compose.2204.590.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docker/docker-compose.2204.590.yaml diff --git a/docker/docker-compose.2204.590.yaml b/docker/docker-compose.2204.590.yaml new file mode 100644 index 0000000..4a6bf8d --- /dev/null +++ b/docker/docker-compose.2204.590.yaml @@ -0,0 +1,19 @@ +version: "3" + +services: + runtime-setup: + image: &image swift-openapi-ahc:22.04-5.9.0 + build: + args: + ubuntu_version: "jammy" + swift_version: "5.9.0" + + test: + image: *image + 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 From 410d691db302f099f1c4ca390d2be53080049d69 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Fri, 1 Dec 2023 13:36:21 +0100 Subject: [PATCH 27/40] Explicit dependency on HTTPTypes (#34) ### Motivation Recent SwiftPM versions seem to be a bit stricter about using (i.e., `import ...`) transitive dependencies without explicitly declaring them as direct dependencies. ### Modifications Explicitly depend on the HTTPTypes module from swift-http-types. ### Result More explicitly declare the dependency graph. ### Test Plan All tests pass. --- Package.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Package.swift b/Package.swift index 70b999c..486dc12 100644 --- a/Package.swift +++ b/Package.swift @@ -37,6 +37,7 @@ let package = Package( .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", exact: "1.0.0-alpha.1"), + .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], targets: [ @@ -44,6 +45,7 @@ let package = Package( name: "OpenAPIAsyncHTTPClient", dependencies: [ .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + .product(name: "HTTPTypes", package: "swift-http-types"), .product(name: "AsyncHTTPClient", package: "async-http-client"), .product(name: "NIOFoundationCompat", package: "swift-nio"), ], From bdb9c8fa6c1544cfaa08487ac0a0ffc462ddb4d6 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Mon, 11 Dec 2023 10:34:01 +0000 Subject: [PATCH 28/40] Add issue template, redirecting to swift-openapi-generator issues (#36) ### Motivation We centralize the issues for all the repos in the Swift OpenAPI Generator project in the generator repo. Using an issue template will make this even clearer, because it will allow people to use the normal Github workflow to discover the process and provide a link to where to file their issue. ### Modifications Add issue template, redirecting to swift-openapi-generator issues. ### Result When people try and file an issue, they'll be presented with a button that takes them to the generator repo issues page. ### Test Plan Manual. --- .github/ISSUE_TEMPLATE/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..548a1a8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,6 @@ +blank_issues_enabled: false +contact_links: + - name: 🐞 Open an issue on the Swift OpenAPI Generator repository + url: https://github.com/apple/swift-openapi-generator/issues + about: > + Issues for all repositories in the Swift OpenAPI Generator project are centralized in the swift-openapi-generator repository. From abfe558a66992ef1e896a577010f957915f30591 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 11 Dec 2023 14:04:24 +0100 Subject: [PATCH 29/40] Prep 1.0 (#37) ### Motivation Prep 1.0 - docs. ### Modifications See above. ### Result Updated for 1.0. ### Test Plan Previewed locally. --- Package.swift | 2 +- README.md | 14 +++----------- .../AsyncHTTPClientTransport.swift | 11 ++--------- .../Documentation.docc/Documentation.md | 13 ++----------- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/Package.swift b/Package.swift index 486dc12..c1d69ba 100644 --- a/Package.swift +++ b/Package.swift @@ -36,7 +36,7 @@ let package = Package( dependencies: [ .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", exact: "1.0.0-alpha.1"), + .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], diff --git a/README.md b/README.md index 140a9f1..c8224ce 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # AsyncHTTPClient Transport for Swift OpenAPI Generator [![](https://img.shields.io/badge/docc-read_documentation-blue)](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client/documentation) +[![](https://img.shields.io/github/v/release/swift-server/swift-openapi-async-http-client)](https://github.com/swift-server/swift-openapi-async-http-client/releases) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswift-server%2Fswift-openapi-async-http-client%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswift-server%2Fswift-openapi-async-http-client%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client) @@ -18,28 +19,19 @@ Use the transport with client code generated by [Swift OpenAPI Generator](https: Add the package dependency in your `Package.swift`: ```swift -.package( - url: "https://github.com/swift-server/swift-openapi-async-http-client", - exact: "1.0.0-alpha.1" -), +.package(url: "https://github.com/swift-server/swift-openapi-async-http-client", from: "1.0.0"), ``` -Note that this repository does not have a 1.0 tag yet, so the API is not stable. - Next, in your target, add `OpenAPIAsyncHTTPClient` to your dependencies: ```swift .target(name: "MyTarget", dependencies: [ .product(name: "OpenAPIAsyncHTTPClient", package: "swift-openapi-async-http-client"), -], +]), ``` Then, to get started, check out `AsyncHTTPClientTransport`. -## Reporting issues - -Please report any issues related to this library in the [swift-openapi-generator](https://github.com/apple/swift-openapi-generator/issues) repository. - ## Documentation To learn more, check out the full [documentation](https://swiftpackageindex.com/swift-server/swift-openapi-async-http-client/documentation). diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index a43a074..d16220e 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -35,17 +35,11 @@ import protocol Foundation.LocalizedError /// /// 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 -/// on the `Servers` type, for example: -/// -/// let serverURL = try Servers.server1() -/// /// Instantiate the `Client` type generated by the Swift OpenAPI Generator for /// your provided OpenAPI document. For example: /// /// let client = Client( -/// serverURL: serverURL, +/// serverURL: URL(string: "https://example.com/")!, /// transport: transport /// ) /// @@ -53,8 +47,7 @@ import protocol Foundation.LocalizedError /// example, if the OpenAPI document contains an HTTP operation with /// the identifier `checkHealth`, call it from Swift with: /// -/// let response = try await client.checkHealth(.init()) -/// // ... +/// let response = try await client.checkHealth() /// /// ### Provide a custom Client /// diff --git a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md index f41c431..f4eb007 100644 --- a/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md +++ b/Sources/OpenAPIAsyncHTTPClient/Documentation.docc/Documentation.md @@ -18,28 +18,19 @@ Use the transport with client code generated by [Swift OpenAPI Generator](https: Add the package dependency in your `Package.swift`: ```swift -.package( - url: "https://github.com/swift-server/swift-openapi-async-http-client", - exact: "1.0.0-alpha.1" -), +.package(url: "https://github.com/swift-server/swift-openapi-async-http-client", from: "1.0.0"), ``` -Note that this repository does not have a 1.0 tag yet, so the API is not stable. - Next, in your target, add `OpenAPIAsyncHTTPClient` to your dependencies: ```swift .target(name: "MyTarget", dependencies: [ .product(name: "OpenAPIAsyncHTTPClient", package: "swift-openapi-async-http-client"), -], +]), ``` Then, to get started, check out ``AsyncHTTPClientTransport``. -### Reporting issues - -Please report any issues related to this library in the [swift-openapi-generator](https://github.com/apple/swift-openapi-generator/issues) repository. - ## Topics ### Usage From 7b96b1d08ed186fdd846040c3e9f25b98d383dbd Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 3 Oct 2024 17:51:54 +0200 Subject: [PATCH 30/40] Adopt AHC's .shared singleton as the default Client (#39) ### Motivation As a convenience when you don't need to create a custom AHC Client instance, we provide a singleton client as the default. AHC added their own `Client.shared` singleton, so let's adopt that and remove the transport's internal singleton, which was used for the same purpose. ### Modifications - Replaced the tranport's internal singleton with the AHC-provided one. - Use Int64 directly and skip conversions now that AHC also uses Int64 for the body byte size. ### Result - No internal singleton is created now, possibly avoiding having two AHC singletons in a given process. - Fixed a warning around Int/Int64 conversion. ### Test Plan Unit tests still pass. --- Package.swift | 2 +- .../AsyncHTTPClientTransport.swift | 26 +++++++++---------- docker/docker-compose.2204.main.yaml | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Package.swift b/Package.swift index c1d69ba..21c12ed 100644 --- a/Package.swift +++ b/Package.swift @@ -35,7 +35,7 @@ let package = Package( ], dependencies: [ .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/swift-server/async-http-client.git", from: "1.23.0"), .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"), .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 d16220e..39b79d3 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -62,26 +62,27 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// The HTTP client used for performing HTTP calls. public var client: HTTPClient - /// The default shared HTTP client. - /// - /// This is a workaround for the lack of a shared client - /// in AsyncHTTPClient. Do not use this value directly, outside of - /// the `Configuration.init(client:timeout:)` initializer, as it will - /// likely be removed in the future. - private static let sharedClient: HTTPClient = .init() - /// The default request timeout. public var timeout: TimeAmount /// Creates a new configuration with the specified client and timeout. /// - Parameters: /// - client: The underlying client used to perform HTTP operations. - /// Provide nil to use the shared internal client. /// - timeout: The request timeout, defaults to 1 minute. - public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) { - self.client = client ?? Self.sharedClient + public init(client: HTTPClient = .shared, timeout: TimeAmount = .minutes(1)) { + self.client = client self.timeout = timeout } + + /// Creates a new configuration with the specified client and timeout. + /// - Parameters: + /// - client: The underlying client used to perform HTTP operations. + /// Provide nil to use the shared client. + /// - timeout: The request timeout, defaults to 1 minute. + @available(*, deprecated, message: "Use the initializer with a non-optional client parameter.") + @_disfavoredOverload public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) { + self.init(client: client ?? .shared, timeout: timeout) + } } /// A request to be sent by the transport. @@ -174,8 +175,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { let length: HTTPClientRequest.Body.Length switch body.length { case .unknown: length = .unknown - case .known(let count): - if let intValue = Int(exactly: count) { length = .known(intValue) } else { length = .unknown } + case .known(let count): length = .known(count) } clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length) } diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml index b1443e6..323b063 100644 --- a/docker/docker-compose.2204.main.yaml +++ b/docker/docker-compose.2204.main.yaml @@ -10,7 +10,7 @@ services: test: image: *image environment: - - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors + # - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete From 36da108ae37e86d33298278251e267a2e35b12af Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 11 Nov 2024 13:12:03 +0000 Subject: [PATCH 31/40] Migrate to GitHub Actions (#41) Migrate CI to use GitHub Actions. ### Motivation: To migrate to GitHub actions and centralised infrastructure. ### Modifications: Changes of note: * Adopt swiftlang soundness checks, swift version matrix * Remove scripts and docker files which are no longer needed ### Result: Feature parity with old CI. ### Test Plan Execute CI --- .editorconfig | 8 ++ .github/workflows/main.yml | 18 +++++ .github/workflows/pull_request.yml | 27 +++++++ .github/workflows/pull_request_label.yml | 18 +++++ .licenseignore | 36 +++++++++ .spi.yml | 4 +- CONTRIBUTING.md | 24 +----- Package.swift | 16 +--- docker/Dockerfile | 23 ------ docker/docker-compose.2204.510.yaml | 17 ---- docker/docker-compose.2204.59.yaml | 19 ----- docker/docker-compose.2204.590.yaml | 19 ----- docker/docker-compose.2204.main.yaml | 18 ----- docker/docker-compose.yaml | 38 --------- scripts/check-for-broken-symlinks.sh | 37 --------- scripts/check-for-docc-warnings.sh | 40 ---------- scripts/check-for-unacceptable-language.sh | 37 --------- scripts/check-license-headers.sh | 90 ---------------------- scripts/generate-contributors-list.sh | 52 ------------- scripts/run-swift-format.sh | 48 ------------ scripts/soundness.sh | 57 -------------- scripts/unacceptable-language.txt | 15 ---- 22 files changed, 115 insertions(+), 546 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/pull_request_label.yml create mode 100644 .licenseignore delete mode 100644 docker/Dockerfile delete mode 100644 docker/docker-compose.2204.510.yaml delete mode 100644 docker/docker-compose.2204.59.yaml delete mode 100644 docker/docker-compose.2204.590.yaml delete mode 100644 docker/docker-compose.2204.main.yaml delete mode 100644 docker/docker-compose.yaml delete mode 100644 scripts/check-for-broken-symlinks.sh delete mode 100644 scripts/check-for-docc-warnings.sh delete mode 100644 scripts/check-for-unacceptable-language.sh delete mode 100644 scripts/check-license-headers.sh delete mode 100644 scripts/generate-contributors-list.sh delete mode 100755 scripts/run-swift-format.sh delete mode 100755 scripts/soundness.sh delete mode 100644 scripts/unacceptable-language.txt diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..08891d8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..400a1b9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,18 @@ +name: Main + +on: + push: + branches: [main] + schedule: + - cron: "0 8,20 * * *" + +jobs: + unit-tests: + name: Unit tests + uses: apple/swift-nio/.github/workflows/unit_tests.yml@main + with: + linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..50e00f8 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,27 @@ +name: PR + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + soundness: + name: Soundness + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main + with: + license_header_check_project_name: "SwiftOpenAPIGenerator" + + unit-tests: + name: Unit tests + uses: apple/swift-nio/.github/workflows/unit_tests.yml@main + with: + linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete" + # TODO: `enable -Xswiftc -strict-concurrency=complete` + linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -strict-concurrency=complete" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + cxx-interop: + name: Cxx interop + uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main diff --git a/.github/workflows/pull_request_label.yml b/.github/workflows/pull_request_label.yml new file mode 100644 index 0000000..8fd47c1 --- /dev/null +++ b/.github/workflows/pull_request_label.yml @@ -0,0 +1,18 @@ +name: PR label + +on: + pull_request: + types: [labeled, unlabeled, opened, reopened, synchronize] + +jobs: + semver-label-check: + name: Semantic version label check + runs-on: ubuntu-latest + timeout-minutes: 1 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Check for Semantic Version label + uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main diff --git a/.licenseignore b/.licenseignore new file mode 100644 index 0000000..d2535f5 --- /dev/null +++ b/.licenseignore @@ -0,0 +1,36 @@ +.gitignore +**/.gitignore +.licenseignore +.gitattributes +.git-blame-ignore-revs +.mailfilter +.mailmap +.spi.yml +.swift-format +.swiftformatignore +.editorconfig +.github/* +*.md +*.txt +*.yml +*.yaml +*.json +Package.swift +**/Package.swift +Package@-*.swift +**/Package@-*.swift +Package.resolved +**/Package.resolved +Makefile +*.modulemap +**/*.modulemap +**/*.docc/* +*.xcprivacy +**/*.xcprivacy +*.symlink +**/*.symlink +Dockerfile +**/Dockerfile +Snippets/* +dev/git.commit.template +.unacceptablelanguageignore diff --git a/.spi.yml b/.spi.yml index 6c06685..084d5b2 100644 --- a/.spi.yml +++ b/.spi.yml @@ -1,5 +1,5 @@ version: 1 builder: configs: - - documentation_targets: - - OpenAPIAsyncHTTPClient + - documentation_targets: + - OpenAPIAsyncHTTPClient diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0cef7b6..b3387c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,28 +56,10 @@ A good patch is: 3. Documented, adding API documentation as needed to cover new functions and properties. 4. Accompanied by a great commit message, using our commit message template. -### Run `./scripts/soundness.sh` +### Run CI checks locally -The scripts directory contains a [soundness.sh script](https://github.com/swift-server/swift-openapi-async-http-client/blob/main/scripts/soundness.sh) -that enforces additional checks, like license headers and formatting style. - -Please make sure to `./scripts/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail -on minor changes such as a missing `self.` or similar formatting issues. - -For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), which you can do via executing the following command in the project root directory: - -```bash -cat << EOF > .git/hooks/pre-push - -if [[ -f "scripts/soundness.sh" ]]; then - scripts/soundness.sh -fi -EOF -``` - -Which makes the script execute, and only allow the `git push` to complete if the check has passed. - -In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again. +You can run the GitHub Actions workflows locally using +[act](https://github.com/nektos/act). For detailed steps on how to do this please see [https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally](https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally). ## How to contribute your work diff --git a/Package.swift b/Package.swift index 21c12ed..ac0e6a6 100644 --- a/Package.swift +++ b/Package.swift @@ -24,21 +24,13 @@ let swiftSettings: [SwiftSetting] = [ let package = Package( name: "swift-openapi-async-http-client", - platforms: [ - .macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1) - ], - products: [ - .library( - name: "OpenAPIAsyncHTTPClient", - targets: ["OpenAPIAsyncHTTPClient"] - ), - ], + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], + products: [.library(name: "OpenAPIAsyncHTTPClient", targets: ["OpenAPIAsyncHTTPClient"])], dependencies: [ .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.23.0"), .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"), - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], targets: [ .target( @@ -53,9 +45,7 @@ let package = Package( ), .testTarget( name: "OpenAPIAsyncHTTPClientTests", - dependencies: [ - "OpenAPIAsyncHTTPClient", - ], + dependencies: ["OpenAPIAsyncHTTPClient"], swiftSettings: swiftSettings ), ] diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index d90e973..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -ARG swift_version=5.9 -ARG ubuntu_version=jammy -ARG base_image=swift:${swift_version}-${ubuntu_version} - -FROM ${base_image} -ARG swift_version -ARG ubuntu_version - -# set as UTF-8 -RUN apt-get update && apt-get install -y locales locales-all -ENV LC_ALL en_US.UTF-8 -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US.UTF-8 - -# tools -RUN mkdir -p $HOME/.tools -RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile - -# swift-format -ARG swiftformat_version=509.0.0 -RUN git clone --branch $swiftformat_version --depth 1 https://github.com/apple/swift-format $HOME/.tools/swift-format-source -RUN cd $HOME/.tools/swift-format-source && swift build -c release -RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format diff --git a/docker/docker-compose.2204.510.yaml b/docker/docker-compose.2204.510.yaml deleted file mode 100644 index 20a4467..0000000 --- a/docker/docker-compose.2204.510.yaml +++ /dev/null @@ -1,17 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-ahc:22.04-5.10 - build: - args: - base_image: "swiftlang/swift:nightly-5.10-jammy" - - test: - image: *image - environment: - - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - - shell: - image: *image diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml deleted file mode 100644 index 75b3e5a..0000000 --- a/docker/docker-compose.2204.59.yaml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-ahc:22.04-5.9 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.9" - - test: - image: *image - 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.590.yaml b/docker/docker-compose.2204.590.yaml deleted file mode 100644 index 4a6bf8d..0000000 --- a/docker/docker-compose.2204.590.yaml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-ahc:22.04-5.9.0 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.9.0" - - test: - image: *image - 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 deleted file mode 100644 index 323b063..0000000 --- a/docker/docker-compose.2204.main.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-ahc:22.04-main - build: - args: - base_image: "swiftlang/swift:nightly-main-jammy" - - test: - image: *image - 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 deleted file mode 100644 index 0921dad..0000000 --- a/docker/docker-compose.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# NOTE: This file is not designed to be run independently. -# -# Instead, use it with a file for a specific OS and Swift version, for example: -# -# % docker-compose \ -# -f docker/docker-compose.yaml \ -# -f docker/docker-compose.2204.59.yaml \ -# run test -# -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-ahc:default - build: - context: . - dockerfile: Dockerfile - - common: &common - image: *image - depends_on: [runtime-setup] - volumes: - - ~/.ssh:/root/.ssh - - ..:/code:z - working_dir: /code - - soundness: - <<: *common - command: /bin/bash -xcl "swift -version && uname -a && ./scripts/soundness.sh" - - test: - <<: *common - command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} $${STRICT_CONCURRENCY_ARG-}" - - shell: - <<: *common - entrypoint: /bin/bash - diff --git a/scripts/check-for-broken-symlinks.sh b/scripts/check-for-broken-symlinks.sh deleted file mode 100644 index 4df8c92..0000000 --- a/scripts/check-for-broken-symlinks.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -set -euo pipefail - -log() { printf -- "** %s\n" "$*" >&2; } -error() { printf -- "** ERROR: %s\n" "$*" >&2; } -fatal() { error "$@"; exit 1; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -log "Checking for broken symlinks..." -NUM_BROKEN_SYMLINKS=0 -while read -r -d '' file; do - if ! test -e "${REPO_ROOT}/${file}"; then - error "Broken symlink: ${file}" - ((NUM_BROKEN_SYMLINKS++)) - fi -done < <(git -C "${REPO_ROOT}" ls-files -z) - -if [ "${NUM_BROKEN_SYMLINKS}" -gt 0 ]; then - fatal "❌ Found ${NUM_BROKEN_SYMLINKS} symlinks." -fi - -log "✅ Found 0 symlinks." diff --git a/scripts/check-for-docc-warnings.sh b/scripts/check-for-docc-warnings.sh deleted file mode 100644 index 88215d4..0000000 --- a/scripts/check-for-docc-warnings.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -euo pipefail - -log() { printf -- "** %s\n" "$*" >&2; } -error() { printf -- "** ERROR: %s\n" "$*" >&2; } -fatal() { error "$@"; exit 1; } - -log "Checking required environment variables..." -test -n "${DOCC_TARGET:-}" || fatal "DOCC_TARGET unset" - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -swift package --package-path "${REPO_ROOT}" plugin generate-documentation \ - --product "${DOCC_TARGET}" \ - --analyze \ - --level detailed \ - --warnings-as-errors \ - && DOCC_PLUGIN_RC=$? || DOCC_PLUGIN_RC=$? - -if [ "${DOCC_PLUGIN_RC}" -ne 0 ]; then - fatal "❌ Generating documentation produced warnings and/or errors." - exit "${DOCC_PLUGIN_RC}" -fi - -log "✅ Generated documentation with no warnings." diff --git a/scripts/check-for-unacceptable-language.sh b/scripts/check-for-unacceptable-language.sh deleted file mode 100644 index 94f79df..0000000 --- a/scripts/check-for-unacceptable-language.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -set -euo pipefail - -log() { printf -- "** %s\n" "$*" >&2; } -error() { printf -- "** ERROR: %s\n" "$*" >&2; } -fatal() { error "$@"; exit 1; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" -UNACCEPTABLE_LANGUAGE_PATTERNS_PATH="${CURRENT_SCRIPT_DIR}/unacceptable-language.txt" - -log "Checking for unacceptable language..." -PATHS_WITH_UNACCEPTABLE_LANGUAGE=$(git -C "${REPO_ROOT}" grep \ - -l -F -w \ - -f "${UNACCEPTABLE_LANGUAGE_PATTERNS_PATH}" \ - -- \ - ":(exclude)${UNACCEPTABLE_LANGUAGE_PATTERNS_PATH}" \ -) || true | /usr/bin/paste -s -d " " - - -if [ -n "${PATHS_WITH_UNACCEPTABLE_LANGUAGE}" ]; then - fatal "❌ Found unacceptable language in files: ${PATHS_WITH_UNACCEPTABLE_LANGUAGE}." -fi - -log "✅ Found no unacceptable language." diff --git a/scripts/check-license-headers.sh b/scripts/check-license-headers.sh deleted file mode 100644 index 9a52856..0000000 --- a/scripts/check-license-headers.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -set -euo pipefail - -log() { printf -- "** %s\n" "$*" >&2; } -error() { printf -- "** ERROR: %s\n" "$*" >&2; } -fatal() { error "$@"; exit 1; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -EXPECTED_FILE_HEADER_TEMPLATE="@@===----------------------------------------------------------------------===@@ -@@ -@@ This source file is part of the SwiftOpenAPIGenerator open source project -@@ -@@ Copyright (c) YEARS Apple Inc. and the SwiftOpenAPIGenerator project authors -@@ Licensed under Apache License v2.0 -@@ -@@ See LICENSE.txt for license information -@@ See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -@@ -@@ SPDX-License-Identifier: Apache-2.0 -@@ -@@===----------------------------------------------------------------------===@@" - -PATHS_WITH_MISSING_LICENSE=( ) - -read -ra PATHS_TO_CHECK_FOR_LICENSE <<< "$( \ - git -C "${REPO_ROOT}" ls-files -z \ - ":(exclude).github/*" \ - ":(exclude).gitignore" \ - ":(exclude).spi.yml" \ - ":(exclude).swift-format" \ - ":(exclude)CODE_OF_CONDUCT.md" \ - ":(exclude)CONTRIBUTING.md" \ - ":(exclude)CONTRIBUTORS.txt" \ - ":(exclude)LICENSE.txt" \ - ":(exclude)NOTICE.txt" \ - ":(exclude)Package.swift" \ - ":(exclude)README.md" \ - ":(exclude)SECURITY.md" \ - ":(exclude)scripts/unacceptable-language.txt" \ - ":(exclude)docker/*" \ - ":(exclude)**/*.docc/*" \ - | xargs -0 \ -)" - -for FILE_PATH in "${PATHS_TO_CHECK_FOR_LICENSE[@]}"; do - FILE_BASENAME=$(basename -- "${FILE_PATH}") - FILE_EXTENSION="${FILE_BASENAME##*.}" - - case "${FILE_EXTENSION}" in - swift) EXPECTED_FILE_HEADER=$(sed -e 's|@@|//|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}") ;; - yml) EXPECTED_FILE_HEADER=$(sed -e 's|@@|##|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}") ;; - sh) EXPECTED_FILE_HEADER=$(cat <(echo '#!/usr/bin/env bash') <(sed -e 's|@@|##|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}")) ;; - *) fatal "Unsupported file extension for file (exclude or update this script): ${FILE_PATH}" ;; - esac - EXPECTED_FILE_HEADER_LINECOUNT=$(wc -l <<<"${EXPECTED_FILE_HEADER}") - - FILE_HEADER=$(head -n "${EXPECTED_FILE_HEADER_LINECOUNT}" "${FILE_PATH}") - NORMALIZED_FILE_HEADER=$( - echo "${FILE_HEADER}" \ - | sed -e 's/202[3]-202[3]/YEARS/' -e 's/202[3]/YEARS/' \ - ) - - if ! diff -u \ - --label "Expected header" <(echo "${EXPECTED_FILE_HEADER}") \ - --label "${FILE_PATH}" <(echo "${NORMALIZED_FILE_HEADER}") - then - PATHS_WITH_MISSING_LICENSE+=("${FILE_PATH} ") - fi -done - -if [ "${#PATHS_WITH_MISSING_LICENSE[@]}" -gt 0 ]; then - fatal "❌ Found missing license header in files: ${PATHS_WITH_MISSING_LICENSE[*]}." -fi - -log "✅ Found no files with missing license header." diff --git a/scripts/generate-contributors-list.sh b/scripts/generate-contributors-list.sh deleted file mode 100644 index 99f072e..0000000 --- a/scripts/generate-contributors-list.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftNIO open source project -## -## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftNIO project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -eu -here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -contributors=$( cd "$here"/.. && git shortlog -es | cut -f2 | sed 's/^/- /' ) - -cat > "$here/../CONTRIBUTORS.txt" <<- EOF - For the purpose of tracking copyright, this is the list of individuals and - organizations who have contributed source code to SwiftOpenAPIGenerator. - - For employees of an organization/company where the copyright of work done - by employees of that company is held by the company itself, only the company - needs to be listed here. - - ## COPYRIGHT HOLDERS - - - Apple Inc. (all contributors with '@apple.com') - - ### Contributors - - $contributors - - **Updating this list** - - Please do not edit this file manually. It is generated using \`./scripts/generate-contributors-list.sh\`. If a name is misspelled or appearing multiple times: add an entry in \`./.mailmap\` -EOF diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh deleted file mode 100755 index eefa585..0000000 --- a/scripts/run-swift-format.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -set -euo pipefail - -log() { printf -- "** %s\n" "$*" >&2; } -error() { printf -- "** ERROR: %s\n" "$*" >&2; } -fatal() { error "$@"; exit 1; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -FORMAT_COMMAND=(lint --strict) -for arg in "$@"; do - if [ "$arg" == "--fix" ]; then - FORMAT_COMMAND=(format --in-place) - fi -done - -SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" - -"${SWIFTFORMAT_BIN}" "${FORMAT_COMMAND[@]}" \ - --parallel --recursive \ - "${REPO_ROOT}/Sources" "${REPO_ROOT}/Tests" \ - && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? - -if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then - fatal "❌ Running swift-format produced errors. - - To fix, run the following command: - - % ./scripts/run-swift-format.sh --fix - " - exit "${SWIFT_FORMAT_RC}" -fi - -log "✅ Ran swift-format with no errors." diff --git a/scripts/soundness.sh b/scripts/soundness.sh deleted file mode 100755 index 7543915..0000000 --- a/scripts/soundness.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -set -euo pipefail - -log() { printf -- "** %s\n" "$*" >&2; } -error() { printf -- "** ERROR: %s\n" "$*" >&2; } -fatal() { error "$@"; exit 1; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -NUM_CHECKS_FAILED=0 -export DOCC_TARGET=OpenAPIAsyncHTTPClient - -FIX_FORMAT="" -for arg in "$@"; do - if [ "$arg" == "--fix" ]; then - FIX_FORMAT="--fix" - fi -done - -SCRIPT_PATHS=( - "${CURRENT_SCRIPT_DIR}/check-for-broken-symlinks.sh" - "${CURRENT_SCRIPT_DIR}/check-for-unacceptable-language.sh" - "${CURRENT_SCRIPT_DIR}/check-license-headers.sh" - "${CURRENT_SCRIPT_DIR}/check-for-docc-warnings.sh" -) - -for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do - log "Running ${SCRIPT_PATH}..." - if ! bash "${SCRIPT_PATH}"; then - ((NUM_CHECKS_FAILED+=1)) - fi -done - -log "Running swift-format..." -bash "${CURRENT_SCRIPT_DIR}"/run-swift-format.sh $FIX_FORMAT > /dev/null -FORMAT_EXIT_CODE=$? -if [ $FORMAT_EXIT_CODE -ne 0 ]; then - ((NUM_CHECKS_FAILED+=1)) -fi - -if [ "${NUM_CHECKS_FAILED}" -gt 0 ]; then - fatal "❌ ${NUM_CHECKS_FAILED} soundness check(s) failed." -fi - -log "✅ All soundness check(s) passed." diff --git a/scripts/unacceptable-language.txt b/scripts/unacceptable-language.txt deleted file mode 100644 index 6ac4a98..0000000 --- a/scripts/unacceptable-language.txt +++ /dev/null @@ -1,15 +0,0 @@ -blacklist -whitelist -slave -master -sane -sanity -insane -insanity -kill -killed -killing -hang -hung -hanged -hanging From 915aeff168625b0f88a5810ee7ab8e9c00af671b Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Wed, 11 Dec 2024 15:32:13 +0000 Subject: [PATCH 32/40] Enable MemberImportVisibility check on all targets (#43) Enable MemberImportVisibility check on all targets. Use a standard string header and footer to bracket the new block for ease of updating in the future with scripts. --- .swiftformatignore | 1 + Package.swift | 11 +++++++++++ .../Test_AsyncHTTPClientTransport.swift | 1 + 3 files changed, 13 insertions(+) create mode 100644 .swiftformatignore diff --git a/.swiftformatignore b/.swiftformatignore new file mode 100644 index 0000000..ef0b696 --- /dev/null +++ b/.swiftformatignore @@ -0,0 +1 @@ +**Package.swift diff --git a/Package.swift b/Package.swift index ac0e6a6..6cce1a8 100644 --- a/Package.swift +++ b/Package.swift @@ -50,3 +50,14 @@ let package = Package( ), ] ) + +// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // +for target in package.targets { + if target.type != .plugin { + var settings = target.swiftSettings ?? [] + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md + settings.append(.enableUpcomingFeature("MemberImportVisibility")) + target.swiftSettings = settings + } +} +// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // diff --git a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift index 7bd9f41..8c94dd5 100644 --- a/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift +++ b/Tests/OpenAPIAsyncHTTPClientTests/Test_AsyncHTTPClientTransport.swift @@ -14,6 +14,7 @@ import XCTest import OpenAPIRuntime import NIOCore +import NIOHTTP1 import NIOPosix import AsyncHTTPClient @testable import OpenAPIAsyncHTTPClient From cf4ffabaf4eef508b4cda9d1a87b04142ca1466c Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Wed, 18 Dec 2024 14:19:54 +0100 Subject: [PATCH 33/40] Update release.yml (#45) Update the release.yml file with the latest label changes --- .github/release.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/release.yml b/.github/release.yml index 4d18da5..e29eb84 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -2,14 +2,13 @@ changelog: categories: - title: SemVer Major labels: - - semver/major + - ⚠️ semver/major - title: SemVer Minor labels: - - semver/minor + - 🆕 semver/minor - title: SemVer Patch labels: - - semver/patch + - 🔨 semver/patch - title: Other Changes labels: - semver/none - - "*" From fdd7e2f414d5db67cc8f88dc5f08f64e63fe88c6 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Fri, 20 Dec 2024 08:44:25 +0000 Subject: [PATCH 34/40] Use StrictConcurrency=complete in Package.swift and add Swift 6 language mode CI (#44) ### Motivation We're trying to lock in strict concurrency across the package ecosystem and standardise on how that's tested. ### Modifications - Add `StrictConcurrency=complete` feature flag to all targets in the package manifest - Remove now superfluous strict concurrency compiler flag in CI runs - Add a new CI pipeline that tests the package with Swift 6 language mode. ### Result - Package configuration consistent with others adopting strict concurrency. - Swift 6 language mode pipeline established to catch regressions. --- .github/workflows/pull_request.yml | 9 ++++++--- Package.swift | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 50e00f8..aad89ae 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -15,13 +15,16 @@ jobs: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main with: - linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete" - # TODO: `enable -Xswiftc -strict-concurrency=complete` + linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" - linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -strict-concurrency=complete" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" cxx-interop: name: Cxx interop uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main + + swift-6-language-mode: + name: Cxx interop + uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main diff --git a/Package.swift b/Package.swift index 6cce1a8..46e38fe 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,8 @@ import PackageDescription let swiftSettings: [SwiftSetting] = [ // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md // Require `any` for existential types. - .enableUpcomingFeature("ExistentialAny") + .enableUpcomingFeature("ExistentialAny"), + .enableExperimentalFeature("StrictConcurrency=complete"), ] let package = Package( From 93b188b6d6ac09df1f38199d3201b4c720e45b40 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 30 Jan 2025 08:57:56 +0000 Subject: [PATCH 35/40] CI use 6.1 nightlies (#46) CI use 6.1 nightlies now that Swift development is happening in the 6.1 branch --- .github/workflows/main.yml | 2 +- .github/workflows/pull_request.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 400a1b9..e32f32b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,5 +14,5 @@ jobs: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index aad89ae..8dac8d6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -18,7 +18,7 @@ jobs: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" cxx-interop: From a9707bbc51fc6aa0460d8e90464a1e6db7e31ed0 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Fri, 14 Mar 2025 10:17:37 +0000 Subject: [PATCH 36/40] Only apply standard swift settings on valid targets (#48) Only apply standard swift settings on valid targets. The current check ignores plugins but that is not comprehensive enough. --- Package.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 46e38fe..85fcb5d 100644 --- a/Package.swift +++ b/Package.swift @@ -54,11 +54,14 @@ let package = Package( // --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // for target in package.targets { - if target.type != .plugin { + switch target.type { + case .regular, .test, .executable: var settings = target.swiftSettings ?? [] // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md settings.append(.enableUpcomingFeature("MemberImportVisibility")) target.swiftSettings = settings + case .macro, .plugin, .system, .binary: () // not applicable + @unknown default: () // we don't know what to do here, do nothing } } // --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // From da9f6ae5adc81be5d50d1889e6c26b9447a15602 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Fri, 14 Mar 2025 10:24:09 +0000 Subject: [PATCH 37/40] Rename nightly_6_1 params to nightly_next (#47) Rename nightly_6_1 params to nightly_next; see https://github.com/apple/swift-nio/pull/3122 --- .github/workflows/main.yml | 2 +- .github/workflows/pull_request.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e32f32b..6ffefd9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,5 +14,5 @@ jobs: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - linux_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8dac8d6..6ffc2ee 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -18,7 +18,7 @@ jobs: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - linux_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" cxx-interop: From 3de8aee75eec802a79640f94c5d0c4b67640563f Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Wed, 2 Apr 2025 14:34:01 +0100 Subject: [PATCH 38/40] Add static SDK CI workflow (#49) Add static SDK CI workflow which runs on commits to PRs, merges to main and daily on main. --- .github/workflows/main.yml | 5 +++++ .github/workflows/pull_request.yml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ffefd9..f15e944 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,3 +16,8 @@ jobs: linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + static-sdk: + name: Static SDK + # Workaround https://github.com/nektos/act/issues/1875 + uses: apple/swift-nio/.github/workflows/static_sdk.yml@main diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6ffc2ee..45d9a78 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -28,3 +28,8 @@ jobs: swift-6-language-mode: name: Cxx interop uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main + + static-sdk: + name: Static SDK + # Workaround https://github.com/nektos/act/issues/1875 + uses: apple/swift-nio/.github/workflows/static_sdk.yml@main From 4671c106e6fff970d4817355dd8e74c73f0578c7 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Wed, 7 May 2025 10:37:02 +0100 Subject: [PATCH 39/40] Enable Swift 6.1 jobs in CI (#50) Motivation: Swift 6.1 has been released, we should add it to our CI coverage. Modifications: Add additional Swift 6.1 jobs where appropriate in main.yml, pull_request.yml Result: Improved test coverage. --- .github/workflows/main.yml | 1 + .github/workflows/pull_request.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f15e944..7bde6ae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,7 @@ jobs: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 45d9a78..8f0a7f6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -18,6 +18,7 @@ jobs: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" From 77663696af9ed15e0306a42401519c4a24f475b5 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Wed, 7 May 2025 14:07:08 +0100 Subject: [PATCH 40/40] Drop Swift 5.9 (#51) Motivation: Swift 5.9 is no longer supported, we should bump the tools version and remove it from our CI. Modifications: * Bump the Swift tools version to Swift 5.10 * Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml Result: Code reflects our support window. --- .github/workflows/main.yml | 1 - .github/workflows/pull_request.yml | 1 - Package.swift | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7bde6ae..99539f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,6 @@ jobs: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main with: - linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8f0a7f6..d067db9 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -15,7 +15,6 @@ jobs: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main with: - linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" diff --git a/Package.swift b/Package.swift index 85fcb5d..766bb95 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.9 +// swift-tools-version:5.10 //===----------------------------------------------------------------------===// // // This source file is part of the SwiftOpenAPIGenerator open source project