Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix broken swift builds on macOS #89

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions languages/rust/rust-client/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"{projectRoot}/Cargo.lock"
],
"outputs": ["{projectRoot}/target"],
"cache": false,
"options": {
"command": "cargo build",
"cwd": "languages/rust/rust-client"
Expand Down
8 changes: 8 additions & 0 deletions languages/swift/swift-client/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import PackageDescription

let package = Package(
name: "ArriClient",
// platforms: [
// .iOS("13.0"),
// .macCatalyst("13.0"),
// .macOS("10.15"),
// .tvOS("13.0"),
// .visionOS("1.0"),
// .watchOS("6.0")
// ],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
Expand Down
11 changes: 9 additions & 2 deletions languages/swift/swift-client/Sources/ArriClient/ArriClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NIOFoundationCompat
let jsonEncoder = JSONEncoder()
let jsonDecoder = JSONDecoder()

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public func parsedArriHttpRequest<TParams: ArriClientModel, TResponse: ArriClientModel>(
delegate: ArriRequestDelegate,
url: String,
Expand Down Expand Up @@ -238,12 +239,12 @@ public func serializeAny(input: JSON) -> String {


//// Request Delegate ////

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public protocol ArriRequestDelegate {
func handleHTTPRequest(request: ArriHTTPRequest) async throws -> ArriHTTPResponse<Data>
func handleHTTPEventStreamRequest(request: ArriHTTPRequest) async throws -> ArriSSEResponse
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public struct DefaultRequestDelegate: ArriRequestDelegate {
var maxBodyBytes: Int = 1024 * 1024
public init() {}
Expand Down Expand Up @@ -307,6 +308,7 @@ public struct DefaultRequestDelegate: ArriRequestDelegate {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public enum ArriSSEResponse {
case ok(ArriHTTPResponse<HTTPClientResponse.Body>)
case error(ArriHTTPResponse<Data>)
Expand Down Expand Up @@ -386,6 +388,7 @@ public enum ArriResponseErrors: Error {
}

extension URLSession {
@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
func asyncData(with: URLRequest) async throws -> (Data?, HTTPURLResponse) {
return try await withCheckedThrowingContinuation { continuation in
URLSession.shared.dataTask(with: with) {data, response, error in
Expand Down Expand Up @@ -596,10 +599,12 @@ public func sseEventListFromString(input: String, debug: Bool) -> ([RawSSEEvent]
return (events, String(leftover))
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public protocol ArriCancellable {
mutating func cancel() -> ()
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public struct EventSourceOptions<T: ArriClientModel> {
public var onMessage: (T, inout EventSource<T>) -> ()
public var onRequest: ((ArriHTTPRequest, inout EventSource<T>) -> ()) = { _, __ in }
Expand Down Expand Up @@ -666,6 +671,7 @@ public struct EventSourceOptions<T: ArriClientModel> {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public struct EventSource<T: ArriClientModel>: ArriCancellable {
var url: String
var method: String
Expand Down Expand Up @@ -701,6 +707,7 @@ public struct EventSource<T: ArriClientModel>: ArriCancellable {
self.cancelled = true
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public mutating func sendRequest() async {
var urlComponents = URLComponents(string: self.url)
if urlComponents == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import ArriClient

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public class ExampleClient {
let baseURL: String
let delegate: ArriRequestDelegate
Expand Down Expand Up @@ -35,6 +36,7 @@ public class ExampleClient {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public class ExampleClientBooksService {
let baseURL: String
let delegate: ArriRequestDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NIOCore
import NIOFoundationCompat
import SwiftCodegenReference

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
struct CustomRequestDelegate: ArriRequestDelegate {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ArriClient
import SwiftCodegenReference

@main
@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
struct Main {
static func main() async throws {
let client = ExampleClient(
Expand Down
3 changes: 2 additions & 1 deletion languages/swift/swift-codegen/src/procedures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export function swiftServiceFromSchema(
continue;
}
}
return `public class ${serviceName} {
return `@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public class ${serviceName} {
let baseURL: String
let delegate: ArriRequestDelegate
let headers: () -> Dictionary<String, String>
Expand Down
3 changes: 3 additions & 0 deletions tests/clients/swift/Sources/TestClient.g.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import ArriClient

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public class TestClient {
let baseURL: String
let delegate: ArriRequestDelegate
Expand Down Expand Up @@ -30,6 +31,7 @@ public class TestClient {

}

@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public class TestClientTestsService {
let baseURL: String
let delegate: ArriRequestDelegate
Expand Down Expand Up @@ -271,6 +273,7 @@ public class TestClientTestsService {
}


@available(macOS 10.15, iOS 13, tvOS 13, visionOS 1, macCatalyst 13, *)
public class TestClientUsersService {
let baseURL: String
let delegate: ArriRequestDelegate
Expand Down
Loading