Skip to content

Commit 0ce8765

Browse files
authored
Support platforms back to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 (#7)
### Motivation Reduce deployment target by 3 versions to gain more adoption. ### Modifications - Added new deployment targets - Refactor `invokeSession` method to support iOS 13+ - Update `swift-openapi-runtime` version once changes are done [there](apple/swift-openapi-runtime#18). ### Result Deployment target will be reduced by 3 versions.
1 parent 7bd7206 commit 0ce8765

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import PackageDescription
1818
let package = Package(
1919
name: "swift-openapi-urlsession",
2020
platforms: [
21-
.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9),
21+
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6),
2222
],
2323
products: [
2424
.library(
@@ -27,7 +27,7 @@ let package = Package(
2727
),
2828
],
2929
dependencies: [
30-
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.0")),
30+
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.3")),
3131
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
3232
],
3333
targets: [

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ A client transport that uses the [URLSession](https://developer.apple.com/docume
44

55
Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator).
66

7+
## Supported platforms and minimum versions
8+
| macOS | Linux | iOS | tvOS | watchOS |
9+
| :-: | :-: | :-: | :-: | :-: |
10+
| ✅ 10.15+ || ✅ 13+ | ✅ 13+ | ✅ 6+ |
11+
712
## Usage
813

914
Add the package dependency in your `Package.swift`:

Sources/OpenAPIURLSession/Documentation.docc/Documentation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ A client transport that uses the [URLSession](https://developer.apple.com/docume
88

99
Use the transport with client code generated by [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator).
1010

11+
### Supported platforms and minimum versions
12+
| macOS | Linux | iOS | tvOS | watchOS |
13+
| :-: | :-: | :-: | :-: | :-: |
14+
| ✅ 10.15+ || ✅ 13+ | ✅ 13+ | ✅ 6+ |
15+
1116
### Usage
1217

1318
Add the package dependency in your `Package.swift`:

Sources/OpenAPIURLSession/URLSessionTransport.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,28 @@ public struct URLSessionTransport: ClientTransport {
9090
}
9191

9292
private func invokeSession(_ urlRequest: URLRequest) async throws -> (Data, URLResponse) {
93-
#if canImport(FoundationNetworking)
93+
// Using `dataTask(with:completionHandler:)` instead of the async method `data(for:)` of URLSession because the latter is not available on linux platforms
9494
return try await withCheckedThrowingContinuation { continuation in
9595
configuration.session
9696
.dataTask(with: urlRequest) { data, response, error in
97-
if let error = error {
97+
if let error {
9898
continuation.resume(with: .failure(error))
9999
return
100100
}
101+
102+
guard let response else {
103+
continuation.resume(
104+
with: .failure(URLSessionTransportError.noResponse(url: urlRequest.url))
105+
)
106+
return
107+
}
108+
101109
continuation.resume(
102-
with: .success((data ?? Data(), response!))
110+
with: .success((data ?? Data(), response))
103111
)
104112
}
105113
.resume()
106114
}
107-
#else
108-
return try await configuration.session.data(for: urlRequest)
109-
#endif
110115
}
111116
}
112117

@@ -118,6 +123,9 @@ internal enum URLSessionTransportError: Error {
118123

119124
/// Returned `URLResponse` could not be converted to `HTTPURLResponse`.
120125
case notHTTPResponse(URLResponse)
126+
127+
/// Returned `URLResponse` was nil
128+
case noResponse(url: URL?)
121129
}
122130

123131
extension OpenAPIRuntime.Response {
@@ -170,6 +178,8 @@ extension URLSessionTransportError: CustomStringConvertible {
170178
"Invalid request URL from request path: \(request.path), query: \(request.query ?? "<nil>") relative to base URL: \(baseURL.absoluteString)"
171179
case .notHTTPResponse(let response):
172180
return "Received a non-HTTP response, of type: \(String(describing: type(of: response)))"
181+
case .noResponse(let url):
182+
return "Received a nil response for \(url?.absoluteString ?? "<nil URL>")"
173183
}
174184
}
175185
}

0 commit comments

Comments
 (0)