Skip to content

Fixing Swift 6 Compatibility on Linux Issues #107

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

Closed
wants to merge 3 commits into from
Closed
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
33 changes: 21 additions & 12 deletions Sources/OpenAPIRuntime/Conversion/URLExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@
import Foundation

extension URL {
private static func defaultOpenAPIServer () -> Self {
guard let url = URL(string: "/") else { fatalError("Failed to create an URL with the string '/'.") }
return url
}

#if swift(>=6.0)
/// Returns the default server URL of "/".
///
/// Specification: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#fixed-fields
public static let defaultOpenAPIServerURL: Self = {
guard let url = URL(string: "/") else { fatalError("Failed to create an URL with the string '/'.") }
return url
}()

/// Returns a validated server URL, or throws an error.
/// - Parameter string: A URL string.
/// - Throws: If the provided string doesn't convert to URL.
public init(validatingOpenAPIServerURL string: String) throws {
guard let url = Self(string: string) else { throw RuntimeError.invalidServerURL(string) }
self = url
}
public nonisolated(unsafe) static let defaultOpenAPIServerURL: Self = defaultOpenAPIServer()
#else
/// Returns the default server URL of "/".
///
/// Specification: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#fixed-fields
public static let defaultOpenAPIServerURL: Self = defaultOpenAPIServer()
#endif

/// Returns a validated server URL, or throws an error.
/// - Parameter string: A URL string.
/// - Throws: If the provided string doesn't convert to URL.
public init(validatingOpenAPIServerURL string: String) throws {
guard let url = Self(string: string) else { throw RuntimeError.invalidServerURL(string) }
self = url
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,17 @@ extension MultipartFramesToRawPartsSequence {
switch stateMachine.nextFromPartSequence() {
case .returnNil: return nil
case .fetchFrame:
let frame : Upstream.AsyncIterator.Element?
var upstream = upstream
let frame = try await upstream.next()
if #available(macOS 15, iOS 18.0, tvOS 18.0, watchOS 11.0, macCatalyst 18.0, visionOS 2.0, *) {
#if compiler(>=6.0)
frame = try await upstream.next(isolation: self)
#else
frame = try await upstream.next()
#endif
} else {
frame = try await upstream.next()
}
self.upstream = upstream
switch stateMachine.partReceivedFrame(frame) {
case .returnNil: return nil
Expand All @@ -365,8 +374,17 @@ extension MultipartFramesToRawPartsSequence {
switch stateMachine.nextFromBodySubsequence() {
case .returnNil: return nil
case .fetchFrame:
let frame : Upstream.AsyncIterator.Element?
var upstream = upstream
let frame = try await upstream.next()
if #available(macOS 15, iOS 18.0, tvOS 18.0, watchOS 11.0, macCatalyst 18.0, visionOS 2.0, *) {
#if compiler(>=6.0)
frame = try await upstream.next(isolation: self)
#else
frame = try await upstream.next()
#endif
} else {
frame = try await upstream.next()
}
self.upstream = upstream
switch stateMachine.bodyReceivedFrame(frame) {
case .returnNil: return nil
Expand Down
23 changes: 19 additions & 4 deletions Sources/OpenAPIRuntime/URICoder/Serialization/URISerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,34 @@ struct URISerializer {
}

extension CharacterSet {

#if swift(>=6.0)
/// A character set of unreserved symbols only from RFC 6570 (excludes
/// alphanumeric characters).
fileprivate nonisolated(unsafe) static let unreservedSymbols: CharacterSet = .init(charactersIn: "-._~")

/// A character set of unreserved characters from RFC 6570.
fileprivate nonisolated(unsafe) static let unreserved: CharacterSet = .alphanumerics.union(unreservedSymbols)

/// A character set with only the space character.
fileprivate nonisolated(unsafe) static let space: CharacterSet = .init(charactersIn: " ")

/// A character set of unreserved characters and a space.
fileprivate nonisolated(unsafe) static let unreservedAndSpace: CharacterSet = .unreserved.union(space)
#else

/// A character set of unreserved symbols only from RFC 6570 (excludes
/// alphanumeric characters).
fileprivate static let unreservedSymbols: CharacterSet = .init(charactersIn: "-._~")

/// A character set of unreserved characters from RFC 6570.
fileprivate static let unreserved: CharacterSet = .alphanumerics.union(unreservedSymbols)

/// A character set with only the space character.
fileprivate static let space: CharacterSet = .init(charactersIn: " ")

/// A character set of unreserved characters and a space.
fileprivate static let unreservedAndSpace: CharacterSet = .unreserved.union(space)
#endif
}

extension URISerializer {
Expand Down