Skip to content

Commit

Permalink
use newer if let syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Oct 3, 2024
1 parent 8afee98 commit f80f2e3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 85 deletions.
12 changes: 6 additions & 6 deletions Sources/OpenAPIKit/JSONReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,19 @@ extension JSONReference: Decodable {
}
self = .internal(internalReference)
} else {
let externalReferenceCandidate: URL?
let externalReference: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: referenceString, encodingInvalidCharacters: false)
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
externalReferenceCandidate = URL(string: referenceString, encodingInvalidCharacters: false)
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
} else {
externalReferenceCandidate = URL(string: referenceString)
externalReference = URL(string: referenceString)
}
#else
externalReferenceCandidate = URL(string: referenceString)
externalReference = URL(string: referenceString)
#endif
guard let externalReference = externalReferenceCandidate else {
guard let externalReference else {
throw InconsistencyError(
subjectName: "JSON Reference",
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
Expand Down
38 changes: 19 additions & 19 deletions Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
url = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
url = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
#else
url = URL(string: string)
#endif
guard let url else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -38,19 +38,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
url = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
url = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#else
url = URL(string: string)
#endif
guard let url = urlCandidate else {
guard let url else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down
20 changes: 10 additions & 10 deletions Sources/OpenAPIKit30/JSONReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,19 @@ extension JSONReference: Decodable {
}
self = .internal(internalReference)
} else {
let externalReferenceCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: referenceString, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let externalReference: URL?
#if canImport(FoundationEssentials)
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
externalReferenceCandidate = URL(string: referenceString, encodingInvalidCharacters: false)
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
} else {
externalReferenceCandidate = URL(string: referenceString)
externalReference = URL(string: referenceString)
}
#else
externalReferenceCandidate = URL(string: referenceString)
#endif
guard let externalReference = externalReferenceCandidate else {
#else
externalReference = URL(string: referenceString)
#endif
guard let externalReference else {
throw InconsistencyError(
subjectName: "JSON Reference",
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
Expand Down
40 changes: 20 additions & 20 deletions Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
url = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
url = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
#else
url = URL(string: string)
#endif
guard let url else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -38,19 +38,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
url = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
url = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
#else
url = URL(string: string)
#endif
guard let url else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down
20 changes: 10 additions & 10 deletions Sources/OpenAPIKitCore/URLTemplate/URLTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ public struct URLTemplate: Hashable, RawRepresentable {
/// Templated URLs with variables in them will not be valid URLs
/// and are therefore guaranteed to return `nil`.
public var url: URL? {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: rawValue, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: rawValue, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: rawValue, encodingInvalidCharacters: false)
url = URL(string: rawValue, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: rawValue)
url = URL(string: rawValue)
}
#else
urlCandidate = URL(string: rawValue)
#endif
return urlCandidate
#else
url = URL(string: rawValue)
#endif
return url
}

/// Get the names of all variables in the URL Template.
Expand Down
40 changes: 20 additions & 20 deletions Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
url = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
url = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
#else
url = URL(string: string)
#endif
guard let url else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -37,19 +37,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let url: URL?
#if canImport(FoundationEssentials)
url = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
url = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
url = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
#else
url = URL(string: string)
#endif
guard let url else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down

0 comments on commit f80f2e3

Please sign in to comment.