From 672a89f4860f9b39508c4e83fe24e2b98991a71e Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 27 Nov 2023 15:08:10 +0100 Subject: [PATCH 1/3] Prep for 1.0 alpha, adapted to runtime changes in main --- Package.swift | 2 +- Sources/OpenAPIURLSession/URLSessionTransport.swift | 3 +-- .../HTTPBodyOutputStreamTests.swift | 10 +++++----- .../URLSessionTransportTests.swift | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Package.swift b/Package.swift index de0994e..bd6f60c 100644 --- a/Package.swift +++ b/Package.swift @@ -46,7 +46,7 @@ let package = Package( ), ], dependencies: [ - .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"), .package(url: "https://github.com/apple/swift-collections", from: "1.0.0"), ], diff --git a/Sources/OpenAPIURLSession/URLSessionTransport.swift b/Sources/OpenAPIURLSession/URLSessionTransport.swift index d618d69..aaf5bda 100644 --- a/Sources/OpenAPIURLSession/URLSessionTransport.swift +++ b/Sources/OpenAPIURLSession/URLSessionTransport.swift @@ -142,8 +142,7 @@ extension HTTPBody.Length { if urlResponse.expectedContentLength == -1 { self = .unknown } else { - // TODO: Content-Length will change to Int64: https://github.com/apple/swift-openapi-generator/issues/354 - self = .known(Int(urlResponse.expectedContentLength)) + self = .known(urlResponse.expectedContentLength) } } } diff --git a/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift b/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift index 3a443a7..40b0033 100644 --- a/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift +++ b/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift @@ -30,7 +30,7 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: false) - let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single) + let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -77,7 +77,7 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single) + let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -129,7 +129,7 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single) + let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -183,7 +183,7 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single) + let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -240,7 +240,7 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single) + let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? diff --git a/Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift b/Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift index 6eb6fc6..122c5e9 100644 --- a/Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift +++ b/Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift @@ -146,13 +146,13 @@ class URLSessionTransportPlatformSupportTests: XCTestCase { func testHTTPRedirect( transport: any ClientTransport, - requestBodyIterationBehavior: HTTPBody.IterationBehavior, + requestBodyIterationBehavior: IterationBehavior, expectFailureDueToIterationBehavior: Bool ) async throws { let requestBodyChunks = ["✊", "✊", " ", "knock", " ", "knock!"] let requestBody = HTTPBody( requestBodyChunks.async, - length: .known(requestBodyChunks.joined().lengthOfBytes(using: .utf8)), + length: .known(Int64(requestBodyChunks.joined().lengthOfBytes(using: .utf8))), iterationBehavior: requestBodyIterationBehavior ) From 8ac501318cb02815632a637f07a1c4fac6c15979 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 27 Nov 2023 15:12:23 +0100 Subject: [PATCH 2/3] Formatting --- .../HTTPBodyOutputStreamTests.swift | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift b/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift index 40b0033..bfeac2f 100644 --- a/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift +++ b/Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift @@ -30,7 +30,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: false) - let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) + let requestBody = HTTPBody( + requestByteSequence, + length: .known(Int64(requestBytes.count)), + iterationBehavior: .single + ) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -77,7 +81,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) + let requestBody = HTTPBody( + requestByteSequence, + length: .known(Int64(requestBytes.count)), + iterationBehavior: .single + ) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -129,7 +137,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) + let requestBody = HTTPBody( + requestByteSequence, + length: .known(Int64(requestBytes.count)), + iterationBehavior: .single + ) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -183,7 +195,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) + let requestBody = HTTPBody( + requestByteSequence, + length: .known(Int64(requestBytes.count)), + iterationBehavior: .single + ) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? @@ -240,7 +256,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase { let requestBytes = (0...numBytes).map { UInt8($0) } let requestChunks = requestBytes.chunks(of: chunkSize) let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true) - let requestBody = HTTPBody(requestByteSequence, length: .known(Int64(requestBytes.count)), iterationBehavior: .single) + let requestBody = HTTPBody( + requestByteSequence, + length: .known(Int64(requestBytes.count)), + iterationBehavior: .single + ) // Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure. var inputStream: InputStream? From 5f1c54c49f6cf3d061af144458c1935e06d9bd15 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 27 Nov 2023 15:23:52 +0100 Subject: [PATCH 3/3] Move to Swift 5.9 as the minimum version --- Package.swift | 11 +++-------- docker/Dockerfile | 2 +- docker/docker-compose.2204.58.yaml | 19 ------------------- docker/docker-compose.yaml | 2 +- 4 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 docker/docker-compose.2204.58.yaml diff --git a/Package.swift b/Package.swift index bd6f60c..02a69d3 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 @@ -16,14 +16,11 @@ import Foundation import PackageDescription // General Swift-settings for all targets. -var swiftSettings: [SwiftSetting] = [] - -#if swift(>=5.9) -swiftSettings.append( +var swiftSettings: [SwiftSetting] = [ // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md // Require `any` for existential types. .enableUpcomingFeature("ExistentialAny") -) +] // Strict concurrency is enabled in CI; use this environment variable to enable it locally. if ProcessInfo.processInfo.environment["SWIFT_OPENAPI_STRICT_CONCURRENCY"].flatMap(Bool.init) ?? false { @@ -31,8 +28,6 @@ if ProcessInfo.processInfo.environment["SWIFT_OPENAPI_STRICT_CONCURRENCY"].flatM .define("SWIFT_OPENAPI_STRICT_CONCURRENCY"), .enableExperimentalFeature("StrictConcurrency"), ]) } -#endif - let package = Package( name: "swift-openapi-urlsession", 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 987f3d2..0000000 --- a/docker/docker-compose.2204.58.yaml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-urlsession: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 d1ea158..79aecb1 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"