Skip to content

Commit

Permalink
Fixing issue with Swift 6.0 and DateEncodingStrategy (#8)
Browse files Browse the repository at this point in the history
* Fixing issue with Swift 6.0 and Date Format

* fixing tests with skip

---------

Co-authored-by: Mathew Polzin <matt.polzin@gmail.com>
  • Loading branch information
leogdion and mattpolzin authored Oct 1, 2024
1 parent aa9d56c commit 4abc8cf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
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 canImport(FoundationEssentials) && swift(>=5.10)
throw XCTSkip("Not supported for Swift 5.10+ 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 canImport(FoundationEssentials) && swift(>=5.10)
throw XCTSkip("Not supported for Swift 5.10+ 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

0 comments on commit 4abc8cf

Please sign in to comment.