Skip to content

Commit 0cf86fe

Browse files
committed
Add swiftType accessor to JSONTypeFormat
1 parent 2a1fb04 commit 0cf86fe

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Sources/OpenAPIKit/Schema Object/TypesAndFormats.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ public enum JSONTypeFormat: Equatable {
4646
return .string
4747
}
4848
}
49+
50+
public var swiftType: Any.Type {
51+
switch self {
52+
case .boolean(let format):
53+
return type(of: format).SwiftType.self
54+
case .object(let format):
55+
return type(of: format).SwiftType.self
56+
case .array(let format):
57+
return type(of: format).SwiftType.self
58+
case .number(let format):
59+
return type(of: format).SwiftType.self
60+
case .integer(let format):
61+
return type(of: format).SwiftType.self
62+
case .string(let format):
63+
return type(of: format).SwiftType.self
64+
}
65+
}
4966
}
5067

5168
// MARK: Formats

Tests/OpenAPIKitTests/Schema Object/SchemaObjectTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ final class SchemaObjectTests: XCTestCase {
7272
XCTAssertEqual(dateString.jsonTypeFormat?.jsonType, .string)
7373
XCTAssertEqual(dateTimeString.jsonTypeFormat?.jsonType, .string)
7474
XCTAssertEqual(passwordString.jsonTypeFormat?.jsonType, .string)
75+
76+
// SwiftType
77+
XCTAssert(boolean.jsonTypeFormat?.swiftType == Bool.self)
78+
XCTAssert(object.jsonTypeFormat?.swiftType == AnyCodable.self)
79+
XCTAssert(array.jsonTypeFormat?.swiftType == [AnyCodable].self)
80+
XCTAssert(number.jsonTypeFormat?.swiftType == Double.self)
81+
XCTAssert(floatNumber.jsonTypeFormat?.swiftType == Double.self)
82+
XCTAssert(doubleNumber.jsonTypeFormat?.swiftType == Double.self)
83+
XCTAssert(integer.jsonTypeFormat?.swiftType == Int.self)
84+
XCTAssert(integer32.jsonTypeFormat?.swiftType == Int.self)
85+
XCTAssert(integer64.jsonTypeFormat?.swiftType == Int.self)
86+
XCTAssert(string.jsonTypeFormat?.swiftType == String.self)
87+
XCTAssert(byteString.jsonTypeFormat?.swiftType == String.self)
88+
XCTAssert(binaryString.jsonTypeFormat?.swiftType == String.self)
89+
XCTAssert(dateString.jsonTypeFormat?.swiftType == String.self)
90+
XCTAssert(dateTimeString.jsonTypeFormat?.swiftType == String.self)
91+
XCTAssert(passwordString.jsonTypeFormat?.swiftType == String.self)
7592
}
7693

7794
func test_required() {

0 commit comments

Comments
 (0)