Skip to content

Commit

Permalink
Merge branch 'main' into release/4_0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Oct 3, 2024
2 parents 198d90d + 03840ad commit 8afee98
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 16 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
- swift:5.9-jammy
- swift:5.10-focal
- swift:5.10-jammy
- swift:6.0-focal
- swift:6.0-jammy
- swift:6.0-noble
- swiftlang/swift:nightly-focal
- swiftlang/swift:nightly-jammy
container: ${{ matrix.image }}
Expand All @@ -28,7 +31,13 @@ jobs:
- name: Run tests
run: swift test
osx:
runs-on: macOS-13
strategy:
fail-fast: false
matrix:
os:
- macos-14
- macos-15
runs-on: ${{ matrix.os }}
steps:
- name: Select latest available Xcode
uses: maxim-lobanov/setup-xcode@v1
Expand Down
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 externalReferenceCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = 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)
} else {
externalReferenceCandidate = URL(string: referenceString)
}
#else
externalReferenceCandidate = URL(string: referenceString)
#endif
guard let externalReference = externalReferenceCandidate else {
throw InconsistencyError(
subjectName: "JSON Reference",
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
Expand Down
28 changes: 26 additions & 2 deletions Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
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 externalReferenceCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = 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)
} else {
externalReferenceCandidate = URL(string: referenceString)
}
#else
externalReferenceCandidate = URL(string: referenceString)
#endif
guard let externalReference = externalReferenceCandidate else {
throw InconsistencyError(
subjectName: "JSON Reference",
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
Expand Down
28 changes: 26 additions & 2 deletions Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down
14 changes: 13 additions & 1 deletion Sources/OpenAPIKitCore/URLTemplate/URLTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +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? {
return URL(string: rawValue)
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: rawValue)
}
#else
urlCandidate = URL(string: rawValue)
#endif
return urlCandidate
}

/// Get the names of all variables in the URL Template.
Expand Down
28 changes: 26 additions & 2 deletions Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -25,7 +37,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
urlCandidate = 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)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down
5 changes: 4 additions & 1 deletion Tests/OpenAPIKit30RealSpecSuite/GitHubAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ final class GitHubAPICampatibilityTests: XCTestCase {
}
}

func test_successfullyParsedDocument() {
func test_successfullyParsedDocument() throws {
#if os(Linux) && compiler(>=6.0)
throw XCTSkip("Swift bug causes CI failure currently (line 48): failed - The operation could not be completed. The file doesn’t exist.")
#endif
switch githubAPI {
case nil:
XCTFail("Did not attempt to pull GitHub API documentation like expected.")
Expand Down
5 changes: 4 additions & 1 deletion Tests/OpenAPIKit30RealSpecSuite/GoogleBooksAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ final class GoogleBooksAPICampatibilityTests: XCTestCase {
}
}

func test_successfullyParsedDocument() {
func test_successfullyParsedDocument() throws {
#if os(Linux) && compiler(>=6.0)
throw XCTSkip("Swift bug causes CI failure currently (line 48): failed - The operation could not be completed. The file doesn’t exist.")
#endif
switch booksAPI {
case nil:
XCTFail("Did not attempt to pull Google Books API documentation like expected.")
Expand Down
5 changes: 4 additions & 1 deletion Tests/OpenAPIKit30RealSpecSuite/PetStoreAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ final class PetStoreAPICampatibilityTests: XCTestCase {
}
}

func test_successfullyParsedDocument() {
func test_successfullyParsedDocument() throws {
#if os(Linux) && compiler(>=6.0)
throw XCTSkip("Swift bug causes CI failure currently (line 48): failed - The operation could not be completed. The file doesn’t exist.")
#endif
switch petStoreAPI {
case nil:
XCTFail("Did not attempt to pull Pet Store API documentation like expected.")
Expand Down
5 changes: 4 additions & 1 deletion Tests/OpenAPIKit30RealSpecSuite/TomTomAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ final class TomTomAPICampatibilityTests: XCTestCase {
}
}

func test_successfullyParsedDocument() {
func test_successfullyParsedDocument() throws {
#if os(Linux) && compiler(>=6.0)
throw XCTSkip("Swift bug causes CI failure currently (line 43): failed - The operation could not be completed. The file doesn’t exist.")
#endif
switch tomtomAPI {
case nil:
XCTFail("Did not attempt to pull TomTom API documentation like expected.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ final class ValidationConvenienceTests: XCTestCase {
)
}

func test_subject_unwrapAndlookup() {
func test_subject_unwrapAndlookup() throws {
let v = Validation<OpenAPI.Parameter>(
description: "parameter is named test",
check: \.name == "test"
Expand Down Expand Up @@ -358,6 +358,13 @@ final class ValidationConvenienceTests: XCTestCase {
XCTAssertFalse(
unwrapAndLookup(\OpenAPI.Document.paths["/test"]?.pathItemValue?.parameters[2], thenApply: v)(context).isEmpty
)
#if os(macOS)
if #available(macOS 15.0, *) {
// this is just here because if #unavailable inside this block causes a compilation failure prior to Swift 5.6 on Linux :/
} else {
throw XCTSkip("Skipping due to Swift/macOS bug resulting in error (line 368): throwing \"std::bad_alloc: std::bad_alloc\"")
}
#endif
// nil keypath
XCTAssertFalse(
unwrapAndLookup(\OpenAPI.Document.paths["/test2"]?.pathItemValue?.parameters.first, thenApply: v)(context).isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ final class ValidationConvenienceTests: XCTestCase {
)
}

func test_subject_unwrapAndlookup() {
func test_subject_unwrapAndlookup() throws {
let v = Validation<OpenAPI.Parameter>(
description: "parameter is named test",
check: \.name == "test"
Expand Down Expand Up @@ -358,6 +358,13 @@ final class ValidationConvenienceTests: XCTestCase {
XCTAssertFalse(
unwrapAndLookup(\OpenAPI.Document.paths["/test"]?.pathItemValue?.parameters[2], thenApply: v)(context).isEmpty
)
#if os(macOS)
if #available(macOS 15.0, *) {
// this is just here because if #unavailable inside this block causes a compilation failure prior to Swift 5.6 on Linux :/
} else {
throw XCTSkip("Skipping due to Swift/macOS bug resulting in error (line 368): throwing \"std::bad_alloc: std::bad_alloc\"")
}
#endif
// nil keypath
XCTAssertFalse(
unwrapAndLookup(\OpenAPI.Document.paths["/test2"]?.pathItemValue?.parameters.first, thenApply: v)(context).isEmpty
Expand Down

0 comments on commit 8afee98

Please sign in to comment.