diff --git a/Sources/OpenAPIKit/JSONReference.swift b/Sources/OpenAPIKit/JSONReference.swift index ba66b671a..3a5d24e07 100644 --- a/Sources/OpenAPIKit/JSONReference.swift +++ b/Sources/OpenAPIKit/JSONReference.swift @@ -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)'", diff --git a/Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift b/Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift index ae5fd9fb5..d750d99de 100644 --- a/Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift +++ b/Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift @@ -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", @@ -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", diff --git a/Sources/OpenAPIKit30/JSONReference.swift b/Sources/OpenAPIKit30/JSONReference.swift index e1d85c684..e39883bc5 100644 --- a/Sources/OpenAPIKit30/JSONReference.swift +++ b/Sources/OpenAPIKit30/JSONReference.swift @@ -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)'", diff --git a/Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift b/Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift index ae5fd9fb5..71e3f36a3 100644 --- a/Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift +++ b/Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift @@ -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", @@ -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", diff --git a/Sources/OpenAPIKitCore/URLTemplate/URLTemplate.swift b/Sources/OpenAPIKitCore/URLTemplate/URLTemplate.swift index 0bebbc73c..a962abbd6 100644 --- a/Sources/OpenAPIKitCore/URLTemplate/URLTemplate.swift +++ b/Sources/OpenAPIKitCore/URLTemplate/URLTemplate.swift @@ -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. diff --git a/Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift b/Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift index a1402ddb8..db12e7ed1 100644 --- a/Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift +++ b/Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift @@ -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", @@ -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",