Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/OpenAPIKit30ErrorReportingTests/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
import Foundation
@preconcurrency import Yams

let testDecoder = YAMLDecoder()
var testDecoder: YAMLDecoder { YAMLDecoder() }
14 changes: 7 additions & 7 deletions Tests/OpenAPIKit30Tests/Schema Object/JSONSchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1057,15 +1057,15 @@ final class SchemaObjectTests: XCTestCase {

func test_withInitalAllowedValues() {
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true, allowedValues: [false]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, allowedValues: [.init([:])]), .init(properties: [:]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, allowedValues: [.init(emptyStringDict)]), .init(properties: [:]))
let array = JSONSchema.array(.init(format: .unspecified, required: true, allowedValues: [.init([false])]), .init(items: .boolean(.init(format: .unspecified, required: true))))
let number = JSONSchema.number(.init(format: .unspecified, required: true, allowedValues: [2.5]), .init())
let integer = JSONSchema.integer(.init(format: .unspecified, required: true, allowedValues: [5]), .init())
let string = JSONSchema.string(.init(format: .unspecified, required: true, allowedValues: ["hello"]), .init())
let fragment = JSONSchema.fragment(.init(allowedValues: [false]))

XCTAssertEqual(boolean.allowedValues, [false])
XCTAssertEqual(object.allowedValues, [.init([:])])
XCTAssertEqual(object.allowedValues, [.init(emptyStringDict)])
XCTAssertEqual(array.allowedValues?[0].value as! [Bool], [false])
XCTAssertEqual(number.allowedValues, [2.5])
XCTAssertEqual(integer.allowedValues, [5])
Expand All @@ -1077,7 +1077,7 @@ final class SchemaObjectTests: XCTestCase {
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true))
.with(allowedValues: [false])
let object = JSONSchema.object(.init(format: .unspecified, required: true), .init(properties: [:]))
.with(allowedValues: [.init([:])])
.with(allowedValues: [.init(emptyStringDict)])
let array = JSONSchema.array(.init(format: .unspecified, required: true), .init(items: .boolean(.init(format: .unspecified, required: true))))
.with(allowedValues: [.init([false])])
let number = JSONSchema.number(.init(format: .unspecified, required: true), .init())
Expand Down Expand Up @@ -1118,15 +1118,15 @@ final class SchemaObjectTests: XCTestCase {

func test_withInitalDefaultValue() {
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true, defaultValue: false))
let object = JSONSchema.object(.init(format: .unspecified, required: true, defaultValue: .init([:])), .init(properties: [:]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, defaultValue: .init(emptyStringDict)), .init(properties: [:]))
let array = JSONSchema.array(.init(format: .unspecified, required: true, defaultValue: .init([false])), .init(items: .boolean(.init(format: .unspecified, required: true))))
let number = JSONSchema.number(.init(format: .unspecified, required: true, defaultValue: 2.5), .init())
let integer = JSONSchema.integer(.init(format: .unspecified, required: true, defaultValue: 5), .init())
let string = JSONSchema.string(.init(format: .unspecified, required: true, defaultValue: "hello"), .init())
let fragment = JSONSchema.fragment(.init(defaultValue: false))

XCTAssertEqual(boolean.defaultValue, false)
XCTAssertEqual(object.defaultValue, .init([:]))
XCTAssertEqual(object.defaultValue, .init(emptyStringDict))
XCTAssertEqual(array.defaultValue, .init([false]))
XCTAssertEqual(number.defaultValue, 2.5)
XCTAssertEqual(integer.defaultValue, 5)
Expand All @@ -1138,7 +1138,7 @@ final class SchemaObjectTests: XCTestCase {
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true))
.with(defaultValue: false)
let object = JSONSchema.object(.init(format: .unspecified, required: true), .init(properties: [:]))
.with(defaultValue: .init([:]))
.with(defaultValue: .init(emptyStringDict))
let array = JSONSchema.array(.init(format: .unspecified, required: true), .init(items: .boolean(.init(format: .unspecified, required: true))))
.with(defaultValue: .init([false]))
let number = JSONSchema.number(.init(format: .unspecified, required: true), .init())
Expand Down Expand Up @@ -1178,7 +1178,7 @@ final class SchemaObjectTests: XCTestCase {
}

func test_withInitialExample() {
let object = JSONSchema.object(.init(format: .unspecified, required: true, example: .init([:])), .init(properties: [:]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, example: .init(emptyStringDict)), .init(properties: [:]))
let fragment = JSONSchema.fragment(.init(example: "hi"))

// nonsense
Expand Down
26 changes: 14 additions & 12 deletions Tests/OpenAPIKit30Tests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
@preconcurrency import Yams
import XCTest

fileprivate let foundationTestEncoder = { () -> JSONEncoder in
fileprivate func foundationTestEncoder() -> JSONEncoder {
let encoder = JSONEncoder()
if #available(macOS 10.13, *) {
encoder.dateEncodingStrategy = .iso8601
Expand All @@ -22,25 +22,25 @@ fileprivate let foundationTestEncoder = { () -> JSONEncoder in
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
#endif
return encoder
}()
}

func orderUnstableEncode<T: Encodable>(_ value: T) throws -> Data {
return try foundationTestEncoder.encode(value)
return try foundationTestEncoder().encode(value)
}

func orderUnstableTestStringFromEncoding<T: Encodable>(of entity: T) throws -> String? {
return String(data: try orderUnstableEncode(entity), encoding: .utf8)
}

fileprivate let yamsTestEncoder = { () -> YAMLEncoder in
fileprivate func yamsTestEncoder() -> YAMLEncoder {
return YAMLEncoder()
}()
}

func orderStableYAMLEncode<T: Encodable>(_ value: T) throws -> String {
return try yamsTestEncoder.encode(value)
return try yamsTestEncoder().encode(value)
}

fileprivate func buildFoundationTestDecoder(_ userInfo: [CodingUserInfoKey: Any] = [:]) -> JSONDecoder {
fileprivate func buildFoundationTestDecoder(_ userInfo: [CodingUserInfoKey: any Sendable] = [:]) -> JSONDecoder {
let decoder = JSONDecoder()
decoder.userInfo = userInfo
if #available(macOS 10.12, *) {
Expand All @@ -54,18 +54,18 @@ fileprivate func buildFoundationTestDecoder(_ userInfo: [CodingUserInfoKey: Any]
return decoder
}

fileprivate let foundationTestDecoder = { () -> JSONDecoder in buildFoundationTestDecoder() }()
fileprivate func foundationTestDecoder() -> JSONDecoder { buildFoundationTestDecoder() }

func orderUnstableDecode<T: Decodable>(_ type: T.Type, from data: Data, userInfo : [CodingUserInfoKey: Any] = [:]) throws -> T {
func orderUnstableDecode<T: Decodable>(_ type: T.Type, from data: Data, userInfo : [CodingUserInfoKey: any Sendable] = [:]) throws -> T {
return try buildFoundationTestDecoder(userInfo).decode(T.self, from: data)
}

fileprivate let yamsTestDecoder = { () -> YAMLDecoder in
fileprivate func yamsTestDecoder() -> YAMLDecoder {
return YAMLDecoder()
}()
}

func orderStableDecode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
return try yamsTestDecoder.decode(T.self, from: data)
return try yamsTestDecoder().decode(T.self, from: data)
}

func assertJSONEquivalent(_ str1: String?, _ str2: String?, file: StaticString = #file, line: UInt = #line) {
Expand All @@ -88,3 +88,5 @@ func assertJSONEquivalent(_ str1: String?, _ str2: String?, file: StaticString =
line: line
)
}

let emptyStringDict = [String: String]()
12 changes: 6 additions & 6 deletions Tests/OpenAPIKitCoreTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import XCTest

fileprivate let foundationTestEncoder = { () -> JSONEncoder in
fileprivate func foundationTestEncoder() -> JSONEncoder {
let encoder = JSONEncoder()
if #available(macOS 10.13, *) {
encoder.dateEncodingStrategy = .iso8601
Expand All @@ -21,10 +21,10 @@ fileprivate let foundationTestEncoder = { () -> JSONEncoder in
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
#endif
return encoder
}()
}

func orderUnstableEncode<T: Encodable>(_ value: T) throws -> Data {
return try foundationTestEncoder.encode(value)
return try foundationTestEncoder().encode(value)
}

func orderUnstableTestStringFromEncoding<T: Encodable>(of entity: T) throws -> String? {
Expand All @@ -35,7 +35,7 @@ func orderUnstableTestStringFromEncoding<T: Encodable>(of entity: T) throws -> S
// return try fineJSONTestEncoder.encode(value)
//}

fileprivate let foundationTestDecoder = { () -> JSONDecoder in
fileprivate func foundationTestDecoder() -> JSONDecoder {
let decoder = JSONDecoder()
if #available(macOS 10.12, *) {
decoder.dateDecodingStrategy = .iso8601
Expand All @@ -46,10 +46,10 @@ fileprivate let foundationTestDecoder = { () -> JSONDecoder in
decoder.keyDecodingStrategy = .useDefaultKeys
#endif
return decoder
}()
}

func orderUnstableDecode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
return try foundationTestDecoder.decode(T.self, from: data)
return try foundationTestDecoder().decode(T.self, from: data)
}

//func orderStableDecode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
Expand Down
2 changes: 1 addition & 1 deletion Tests/OpenAPIKitErrorReportingTests/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
import Foundation
@preconcurrency import Yams

let testDecoder = YAMLDecoder()
var testDecoder: YAMLDecoder { YAMLDecoder() }
14 changes: 7 additions & 7 deletions Tests/OpenAPIKitTests/Schema Object/JSONSchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ final class SchemaObjectTests: XCTestCase {
func test_withInitalAllowedValues() {
let null = JSONSchema.null(.init(allowedValues: [nil]))
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true, allowedValues: [false]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, allowedValues: [.init([:])]), .init(properties: [:]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, allowedValues: [.init(emptyStringDict)]), .init(properties: [:]))
let array = JSONSchema.array(.init(format: .unspecified, required: true, allowedValues: [.init([false])]), .init(items: .boolean(.init(format: .unspecified, required: true))))
let number = JSONSchema.number(.init(format: .unspecified, required: true, allowedValues: [2.5]), .init())
let integer = JSONSchema.integer(.init(format: .unspecified, required: true, allowedValues: [5]), .init())
Expand All @@ -1329,7 +1329,7 @@ final class SchemaObjectTests: XCTestCase {

XCTAssertEqual(null.allowedValues?[0].description, "nil")
XCTAssertEqual(boolean.allowedValues, [false])
XCTAssertEqual(object.allowedValues, [.init([:])])
XCTAssertEqual(object.allowedValues, [.init(emptyStringDict)])
XCTAssertEqual(array.allowedValues?[0].value as! [Bool], [false])
XCTAssertEqual(number.allowedValues, [2.5])
XCTAssertEqual(integer.allowedValues, [5])
Expand All @@ -1342,7 +1342,7 @@ final class SchemaObjectTests: XCTestCase {
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true))
.with(allowedValues: [false])
let object = JSONSchema.object(.init(format: .unspecified, required: true), .init(properties: [:]))
.with(allowedValues: [.init([:])])
.with(allowedValues: [.init(emptyStringDict)])
let array = JSONSchema.array(.init(format: .unspecified, required: true), .init(items: .boolean(.init(format: .unspecified, required: true))))
.with(allowedValues: [.init([false])])
let number = JSONSchema.number(.init(format: .unspecified, required: true), .init())
Expand Down Expand Up @@ -1384,7 +1384,7 @@ final class SchemaObjectTests: XCTestCase {
func test_withInitalDefaultValue() {
let null = JSONSchema.null(.init(defaultValue: nil))
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true, defaultValue: false))
let object = JSONSchema.object(.init(format: .unspecified, required: true, defaultValue: .init([:])), .init(properties: [:]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, defaultValue: .init(emptyStringDict)), .init(properties: [:]))
let array = JSONSchema.array(.init(format: .unspecified, required: true, defaultValue: .init([false])), .init(items: .boolean(.init(format: .unspecified, required: true))))
let number = JSONSchema.number(.init(format: .unspecified, required: true, defaultValue: 2.5), .init())
let integer = JSONSchema.integer(.init(format: .unspecified, required: true, defaultValue: 5), .init())
Expand All @@ -1393,7 +1393,7 @@ final class SchemaObjectTests: XCTestCase {

XCTAssertNil(null.defaultValue)
XCTAssertEqual(boolean.defaultValue, false)
XCTAssertEqual(object.defaultValue, .init([:]))
XCTAssertEqual(object.defaultValue, .init(emptyStringDict))
XCTAssertEqual(array.defaultValue, .init([false]))
XCTAssertEqual(number.defaultValue, 2.5)
XCTAssertEqual(integer.defaultValue, 5)
Expand All @@ -1406,7 +1406,7 @@ final class SchemaObjectTests: XCTestCase {
let boolean = JSONSchema.boolean(.init(format: .unspecified, required: true))
.with(defaultValue: false)
let object = JSONSchema.object(.init(format: .unspecified, required: true), .init(properties: [:]))
.with(defaultValue: .init([:]))
.with(defaultValue: .init(emptyStringDict))
let array = JSONSchema.array(.init(format: .unspecified, required: true), .init(items: .boolean(.init(format: .unspecified, required: true))))
.with(defaultValue: .init([false]))
let number = JSONSchema.number(.init(format: .unspecified, required: true), .init())
Expand Down Expand Up @@ -1447,7 +1447,7 @@ final class SchemaObjectTests: XCTestCase {
}

func test_withInitialExample() {
let object = JSONSchema.object(.init(format: .unspecified, required: true, examples: [.init([:])]), .init(properties: [:]))
let object = JSONSchema.object(.init(format: .unspecified, required: true, examples: [.init(emptyStringDict)]), .init(properties: [:]))
let fragment = JSONSchema.fragment(.init(examples: ["hi"]))
let null = JSONSchema.null(.init(examples: ["null"]))

Expand Down
26 changes: 14 additions & 12 deletions Tests/OpenAPIKitTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
@preconcurrency import Yams
import XCTest

fileprivate let foundationTestEncoder = { () -> JSONEncoder in
fileprivate func foundationTestEncoder() -> JSONEncoder {
let encoder = JSONEncoder()
if #available(macOS 10.13, *) {
encoder.dateEncodingStrategy = .iso8601
Expand All @@ -22,25 +22,25 @@ fileprivate let foundationTestEncoder = { () -> JSONEncoder in
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
#endif
return encoder
}()
}

func orderUnstableEncode<T: Encodable>(_ value: T) throws -> Data {
return try foundationTestEncoder.encode(value)
return try foundationTestEncoder().encode(value)
}

func orderUnstableTestStringFromEncoding<T: Encodable>(of entity: T) throws -> String? {
return String(data: try orderUnstableEncode(entity), encoding: .utf8)
}

fileprivate let yamsTestEncoder = { () -> YAMLEncoder in
fileprivate func yamsTestEncoder() -> YAMLEncoder {
return YAMLEncoder()
}()
}

func orderStableYAMLEncode<T: Encodable>(_ value: T) throws -> String {
return try yamsTestEncoder.encode(value)
return try yamsTestEncoder().encode(value)
}

fileprivate func buildFoundationTestDecoder(_ userInfo: [CodingUserInfoKey: Any] = [:]) -> JSONDecoder {
fileprivate func buildFoundationTestDecoder(_ userInfo: [CodingUserInfoKey: any Sendable] = [:]) -> JSONDecoder {
let decoder = JSONDecoder()
decoder.userInfo = userInfo
if #available(macOS 10.12, *) {
Expand All @@ -54,18 +54,18 @@ fileprivate func buildFoundationTestDecoder(_ userInfo: [CodingUserInfoKey: Any]
return decoder
}

fileprivate let foundationTestDecoder = { () -> JSONDecoder in buildFoundationTestDecoder() }()
fileprivate func foundationTestDecoder() -> JSONDecoder { buildFoundationTestDecoder() }

func orderUnstableDecode<T: Decodable>(_ type: T.Type, from data: Data, userInfo : [CodingUserInfoKey: Any] = [:]) throws -> T {
func orderUnstableDecode<T: Decodable>(_ type: T.Type, from data: Data, userInfo : [CodingUserInfoKey: any Sendable] = [:]) throws -> T {
return try buildFoundationTestDecoder(userInfo).decode(T.self, from: data)
}

fileprivate let yamsTestDecoder = { () -> YAMLDecoder in
fileprivate func yamsTestDecoder() -> YAMLDecoder {
return YAMLDecoder()
}()
}

func orderStableDecode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
return try yamsTestDecoder.decode(T.self, from: data)
return try yamsTestDecoder().decode(T.self, from: data)
}

func assertJSONEquivalent(_ str1: String?, _ str2: String?, file: StaticString = #file, line: UInt = #line) {
Expand All @@ -88,3 +88,5 @@ func assertJSONEquivalent(_ str1: String?, _ str2: String?, file: StaticString =
line: line
)
}

let emptyStringDict = [String: String]()