Skip to content

Commit fa75a83

Browse files
authored
Prep for 1.0 alpha, adapted to runtime changes in main (#31)
### 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.
1 parent 7d33846 commit fa75a83

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let package = Package(
4646
),
4747
],
4848
dependencies: [
49-
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.0")),
49+
.package(url: "https://github.com/apple/swift-openapi-runtime", branch: "main"),
5050
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
5151
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
5252
],

Sources/OpenAPIURLSession/URLSessionTransport.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ extension HTTPBody.Length {
142142
if urlResponse.expectedContentLength == -1 {
143143
self = .unknown
144144
} else {
145-
// TODO: Content-Length will change to Int64: https://github.com/apple/swift-openapi-generator/issues/354
146-
self = .known(Int(urlResponse.expectedContentLength))
145+
self = .known(urlResponse.expectedContentLength)
147146
}
148147
}
149148
}

Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift

+25-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
3030
let requestBytes = (0...numBytes).map { UInt8($0) }
3131
let requestChunks = requestBytes.chunks(of: chunkSize)
3232
let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: false)
33-
let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single)
33+
let requestBody = HTTPBody(
34+
requestByteSequence,
35+
length: .known(Int64(requestBytes.count)),
36+
iterationBehavior: .single
37+
)
3438

3539
// Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure.
3640
var inputStream: InputStream?
@@ -77,7 +81,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
7781
let requestBytes = (0...numBytes).map { UInt8($0) }
7882
let requestChunks = requestBytes.chunks(of: chunkSize)
7983
let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true)
80-
let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single)
84+
let requestBody = HTTPBody(
85+
requestByteSequence,
86+
length: .known(Int64(requestBytes.count)),
87+
iterationBehavior: .single
88+
)
8189

8290
// Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure.
8391
var inputStream: InputStream?
@@ -129,7 +137,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
129137
let requestBytes = (0...numBytes).map { UInt8($0) }
130138
let requestChunks = requestBytes.chunks(of: chunkSize)
131139
let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true)
132-
let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single)
140+
let requestBody = HTTPBody(
141+
requestByteSequence,
142+
length: .known(Int64(requestBytes.count)),
143+
iterationBehavior: .single
144+
)
133145

134146
// Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure.
135147
var inputStream: InputStream?
@@ -183,7 +195,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
183195
let requestBytes = (0...numBytes).map { UInt8($0) }
184196
let requestChunks = requestBytes.chunks(of: chunkSize)
185197
let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true)
186-
let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single)
198+
let requestBody = HTTPBody(
199+
requestByteSequence,
200+
length: .known(Int64(requestBytes.count)),
201+
iterationBehavior: .single
202+
)
187203

188204
// Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure.
189205
var inputStream: InputStream?
@@ -240,7 +256,11 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
240256
let requestBytes = (0...numBytes).map { UInt8($0) }
241257
let requestChunks = requestBytes.chunks(of: chunkSize)
242258
let requestByteSequence = MockAsyncSequence(elementsToVend: requestChunks, gatingProduction: true)
243-
let requestBody = HTTPBody(requestByteSequence, length: .known(requestBytes.count), iterationBehavior: .single)
259+
let requestBody = HTTPBody(
260+
requestByteSequence,
261+
length: .known(Int64(requestBytes.count)),
262+
iterationBehavior: .single
263+
)
244264

245265
// Create a pair of bound streams with a tiny buffer to be the bottleneck for backpressure.
246266
var inputStream: InputStream?

Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ class URLSessionTransportPlatformSupportTests: XCTestCase {
146146

147147
func testHTTPRedirect(
148148
transport: any ClientTransport,
149-
requestBodyIterationBehavior: HTTPBody.IterationBehavior,
149+
requestBodyIterationBehavior: IterationBehavior,
150150
expectFailureDueToIterationBehavior: Bool
151151
) async throws {
152152
let requestBodyChunks = ["", "", " ", "knock", " ", "knock!"]
153153
let requestBody = HTTPBody(
154154
requestBodyChunks.async,
155-
length: .known(requestBodyChunks.joined().lengthOfBytes(using: .utf8)),
155+
length: .known(Int64(requestBodyChunks.joined().lengthOfBytes(using: .utf8))),
156156
iterationBehavior: requestBodyIterationBehavior
157157
)
158158

0 commit comments

Comments
 (0)