Skip to content

Commit

Permalink
fix url decoding failure for recent versions of Foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Oct 3, 2024
1 parent a551490 commit 3da4ada
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Sources/OpenAPIKit/JSONReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,19 @@ extension JSONReference: Decodable {
}
self = .internal(internalReference)
} else {
guard let externalReference = URL(string: referenceString) else {
let externalReference: URL?
#if canImport(FoundationEssentials)
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
#elseif os(macOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
} else {
externalReference = URL(string: referenceString)
}
#else
externalReference = URL(string: referenceString)
#endif
guard let externalReference = externalReference else {
throw InconsistencyError(
subjectName: "JSON Reference",
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
Expand Down
14 changes: 13 additions & 1 deletion Sources/OpenAPIKit30/JSONReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,19 @@ extension JSONReference: Decodable {
}
self = .internal(internalReference)
} else {
guard let externalReference = URL(string: referenceString) else {
let externalReference: URL?
#if canImport(FoundationEssentials)
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
#elseif os(macOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
externalReference = URL(string: referenceString, encodingInvalidCharacters: false)
} else {
externalReference = URL(string: referenceString)
}
#else
externalReference = URL(string: referenceString)
#endif
guard let externalReference = externalReference else {
throw InconsistencyError(
subjectName: "JSON Reference",
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
Expand Down

0 comments on commit 3da4ada

Please sign in to comment.