Skip to content

Commit

Permalink
Prep for 1.0 alpha, adapted to runtime changes in main (#31)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
czechboy0 authored Nov 27, 2023
1 parent 7d33846 commit fa75a83
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
Expand Down
3 changes: 1 addition & 2 deletions Sources/OpenAPIURLSession/URLSessionTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(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?
Expand Down Expand Up @@ -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(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?
Expand Down Expand Up @@ -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(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?
Expand Down Expand Up @@ -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(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?
Expand Down Expand Up @@ -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(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?
Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit fa75a83

Please sign in to comment.