diff --git a/Tests/OpenAPIKit30ErrorReportingTests/DocumentErrorTests.swift b/Tests/OpenAPIKit30ErrorReportingTests/DocumentErrorTests.swift index 919c52132..30cedeff6 100644 --- a/Tests/OpenAPIKit30ErrorReportingTests/DocumentErrorTests.swift +++ b/Tests/OpenAPIKit30ErrorReportingTests/DocumentErrorTests.swift @@ -26,6 +26,7 @@ final class DocumentErrorTests: XCTestCase { let openAPIError = OpenAPI.Error(from: error) XCTAssertEqual(openAPIError.localizedDescription, "Expected to find `openapi` key in the root Document object but it is missing.") + XCTAssertEqual(openAPIError.localizedDescription, openAPIError.description) XCTAssertEqual(openAPIError.codingPath.map { $0.stringValue }, []) } } diff --git a/Tests/OpenAPIKit30Tests/Document/DereferencedDocumentTests.swift b/Tests/OpenAPIKit30Tests/Document/DereferencedDocumentTests.swift index d46449530..a1ea8115e 100644 --- a/Tests/OpenAPIKit30Tests/Document/DereferencedDocumentTests.swift +++ b/Tests/OpenAPIKit30Tests/Document/DereferencedDocumentTests.swift @@ -28,14 +28,17 @@ final class DereferencedDocumentTests: XCTestCase { servers: [.init(url: URL(string: "http://website.com")!)], paths: [ "/hello/world": .init( + servers: [.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")])], get: .init( + operationId: "hi", responses: [ 200: .response(description: "success") ] ) ) ], - components: .noComponents + components: .noComponents, + tags: ["hi"] ).locallyDereferenced() XCTAssertEqual(t1.paths.count, 1) @@ -51,6 +54,13 @@ final class DereferencedDocumentTests: XCTestCase { t1.resolvedEndpointsByPath().keys, ["/hello/world"] ) + + XCTAssertEqual(t1.allOperationIds, ["hi"]) + XCTAssertEqual(t1.allServers, [ + .init(url: URL(string: "http://website.com")!), + .init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")]), + ]) + XCTAssertEqual(t1.allTags, ["hi"]) } func test_noSecurityReferencedResponseInPath() throws { diff --git a/Tests/OpenAPIKit30Tests/Validator/ValidatorTests.swift b/Tests/OpenAPIKit30Tests/Validator/ValidatorTests.swift index bc3d4555d..c96acc1cf 100644 --- a/Tests/OpenAPIKit30Tests/Validator/ValidatorTests.swift +++ b/Tests/OpenAPIKit30Tests/Validator/ValidatorTests.swift @@ -1444,6 +1444,12 @@ final class ValidatorTests: XCTestCase { "Inconsistency encountered when parsing ``: \'gzip\' could not be parsed as a Content Type. Content Types should have the format \'/\'." ) XCTAssertEqual(warnings.first?.codingPathString, ".paths[\'/test\'].get.responses.200.content") + XCTAssertNotNil(warnings.first?.underlyingError) + XCTAssertNotNil(warnings.first?.errorCategory) + XCTAssertEqual(warnings.first?.subjectName, "") + XCTAssertEqual(warnings.first?.contextString, "") + + XCTAssertEqual(warnings.first?.localizedDescription, warnings.first?.description) } func test_collectsContentTypeWarningStrict() throws { diff --git a/Tests/OpenAPIKitCoreTests/CallbackURLTests.swift b/Tests/OpenAPIKitCoreTests/CallbackURLTests.swift index 15fe508ae..01f975b70 100644 --- a/Tests/OpenAPIKitCoreTests/CallbackURLTests.swift +++ b/Tests/OpenAPIKitCoreTests/CallbackURLTests.swift @@ -9,7 +9,7 @@ import OpenAPIKitCore import XCTest final class CallbackURLTests: XCTestCase { - func testInit() { + func test_init() { let plainUrl = Shared.CallbackURL(url: URL(string: "https://hello.com")!) XCTAssertEqual(plainUrl.url, URL(string: "https://hello.com")!) XCTAssertEqual(plainUrl.template.variables.count, 0) @@ -19,7 +19,7 @@ final class CallbackURLTests: XCTestCase { XCTAssertEqual(templateUrl?.template.variables, ["$request.path.id"]) } - func testEncode() throws { + func test_encode() throws { let url = Shared.CallbackURL(rawValue: "https://hello.com/item/{$request.path.id}") let result = try orderUnstableTestStringFromEncoding(of: url) @@ -32,7 +32,7 @@ final class CallbackURLTests: XCTestCase { ) } - func testDecode() throws { + func test_decode() throws { let json = #""https://hello.com/item/{$request.path.id}""# let data = json.data(using: .utf8)! diff --git a/Tests/OpenAPIKitCoreTests/ComponentKeyTests.swift b/Tests/OpenAPIKitCoreTests/ComponentKeyTests.swift new file mode 100644 index 000000000..0236e9ee0 --- /dev/null +++ b/Tests/OpenAPIKitCoreTests/ComponentKeyTests.swift @@ -0,0 +1,40 @@ +// +// ComponentKeyTests.swift +// OpenAPIKit +// +// Created by Mathew Polzin on 2/16/25. +// + +import OpenAPIKitCore +import XCTest + +final class ComponentKeyTests: XCTestCase { + func test_init() throws { + let t1 : Shared.ComponentKey = "abcd" + XCTAssertEqual(t1.rawValue, "abcd") + + let t2 = Shared.ComponentKey(rawValue: "abcd") + XCTAssertEqual(t2?.rawValue, "abcd") + + let t3 = Shared.ComponentKey(rawValue: "") + XCTAssertNil(t3) + + let t4 = Shared.ComponentKey(rawValue: "(abcd)") + XCTAssertNil(t4) + + let t5 = try Shared.ComponentKey.forceInit(rawValue: "abcd") + XCTAssertEqual(t5.rawValue, "abcd") + + XCTAssertThrowsError(try Shared.ComponentKey.forceInit(rawValue: nil)) + XCTAssertThrowsError(try Shared.ComponentKey.forceInit(rawValue: "(abcd)")) + } + + func test_problemString() { + let message = Shared.ComponentKey.problem(with: "(abcd)") + + XCTAssertEqual(message, "Keys for components in the Components Object must conform to the regex `^[a-zA-Z0-9\\.\\-_]+$`. '(abcd)' does not..") + + let nonProblem = Shared.ComponentKey.problem(with: "abcd") + XCTAssertNil(nonProblem) + } +} diff --git a/Tests/OpenAPIKitTests/Document/DereferencedDocumentTests.swift b/Tests/OpenAPIKitTests/Document/DereferencedDocumentTests.swift index 941db1093..678223292 100644 --- a/Tests/OpenAPIKitTests/Document/DereferencedDocumentTests.swift +++ b/Tests/OpenAPIKitTests/Document/DereferencedDocumentTests.swift @@ -28,14 +28,17 @@ final class DereferencedDocumentTests: XCTestCase { servers: [.init(url: URL(string: "http://website.com")!)], paths: [ "/hello/world": .init( + servers: [.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")])], get: .init( + operationId: "hi", responses: [ 200: .response(description: "success") ] ) ) ], - components: .noComponents + components: .noComponents, + tags: ["hi"] ).locallyDereferenced() XCTAssertEqual(t1.paths.count, 1) @@ -51,6 +54,13 @@ final class DereferencedDocumentTests: XCTestCase { t1.resolvedEndpointsByPath().keys, ["/hello/world"] ) + + XCTAssertEqual(t1.allOperationIds, ["hi"]) + XCTAssertEqual(t1.allServers, [ + .init(url: URL(string: "http://website.com")!), + .init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")]), + ]) + XCTAssertEqual(t1.allTags, ["hi"]) } func test_noSecurityReferencedResponseInPath() throws {