Skip to content
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

Fixing issue with Swift 6.0 and DateEncodingStrategy #8

Merged
merged 11 commits into from
Oct 1, 2024
14 changes: 9 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- master
- main

jobs:
linux:
Expand All @@ -13,14 +13,18 @@ jobs:
fail-fast: false
matrix:
image:
- swift:5.8-bionic
- swift:5.8-focal
- swift:5.8-jammy
- swift:5.8-amazonlinux2
- swift:5.9-focal
- swift:5.9-jammy
- swift:5.9-amazonlinux2
container: ${{ matrix.image }}
- swift:5.10-focal
- swift:5.10-jammy
- swift:5.10-noble
- swift:6.0-focal
- swift:6.0-jammy
- swift:6.0-noble
container:
image: ${{ matrix.image }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenAPIReflection/Date+OpenAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ extension Date: DateOpenAPISchemaType {
case .iso8601:
return .string(format: .dateTime)

#if !canImport(FoundationEssentials) || swift(<5.10)
case .formatted(let formatter):
let hasTime = formatter.timeStyle != .none
let format: JSONTypeFormat.StringFormat = hasTime ? .dateTime : .date

return .string(format: format)
#endif

@unknown default:
return nil
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenAPIReflection30/Date+OpenAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ extension Date: DateOpenAPISchemaType {
case .iso8601:
return .string(format: .dateTime)

#if !canImport(FoundationEssentials) || swift(<5.10)
case .formatted(let formatter):
let hasTime = formatter.timeStyle != .none
let format: JSONTypeFormat.StringFormat = hasTime ? .dateTime : .date

return .string(format: format)
#endif

@unknown default:
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ final class GenericOpenAPISchemaTests: XCTestCase {
let df1 = DateFormatter()
df1.timeStyle = .none
e4.dateEncodingStrategy = .formatted(df1)

#if os(Linux)
throw XCTSkip("Not supported on Linux.")
#else
let node4 = try DateType.genericOpenAPISchemaGuess(using: e4)

XCTAssertEqual(
Expand All @@ -125,6 +127,7 @@ final class GenericOpenAPISchemaTests: XCTestCase {
]
)
)
#endif
}

func test_nested() throws {
Expand Down
4 changes: 4 additions & 0 deletions Tests/OpenAPIReflectionTests/GenericOpenAPISchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ final class GenericOpenAPISchemaTests: XCTestCase {
let node3 = try DateType.genericOpenAPISchemaGuess(using: e3)

XCTAssertEqual(node2, node3)
#if os(Linux)
throw XCTSkip("Not supported on Linux.")
#else
XCTAssertEqual(
node2,
JSONSchema.object(
Expand Down Expand Up @@ -142,6 +145,7 @@ final class GenericOpenAPISchemaTests: XCTestCase {
]
)
)
#endif
}

func test_nested() throws {
Expand Down
Loading