Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Apr 6, 2024
1 parent 8d90a6d commit 7863815
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/ExternalLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public protocol ExternalLoaderContext {
/// but the same key for all equal objects. In practice, this probably means that any
/// time the same type and URL pair are passed in the same `ComponentKey` should be
/// returned.
static func componentKey<T>(type: T.Type, at: URL) throws -> OpenAPI.ComponentKey
static func componentKey<T>(type: T.Type, at url: URL) throws -> OpenAPI.ComponentKey
}

public protocol ExternallyDereferenceable {
Expand Down
5 changes: 2 additions & 3 deletions Tests/OpenAPIKitTests/Document/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ extension DocumentTests {
return finished
}

mutating func nextComponentKey<T>(type: T.Type, at url: URL, given components: OpenAPIKit.OpenAPI.Components) throws -> OpenAPIKit.OpenAPI.ComponentKey {
static func componentKey<T>(type: T.Type, at url: URL) throws -> OpenAPIKit.OpenAPI.ComponentKey {
// do anything you want here to determine what key the new component should be stored at.
// for the example, we will just transform the URL into a valid components key:
let urlString = url.pathComponents.dropFirst().joined(separator: "_").replacingOccurrences(of: ".", with: "_")
Expand Down Expand Up @@ -1258,8 +1258,7 @@ extension DocumentTests {
}
*/

let context = ExampleLoaderContext()
try await document.externallyDereference(in: context)
try await document.externallyDereference(in: ExampleLoaderContext.self)

// - MARK: After
print(
Expand Down
14 changes: 3 additions & 11 deletions Tests/OpenAPIKitTests/Path Item/PathItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ extension PathItemTests {
// MARK: External Dereferencing Tests
extension PathItemTests {
struct MockLoad: ExternalLoaderContext {
func nextComponentKey<T>(type: T.Type, at url: URL, given components: OpenAPI.Components) -> OpenAPI.ComponentKey {
static func componentKey<T>(type: T.Type, at url: URL) -> OpenAPI.ComponentKey {
"hello-world"
}

Expand All @@ -452,12 +452,6 @@ extension PathItemTests {
}

func test_tmp() async throws {
let components = OpenAPI.Components(
parameters: [
"already-internal":
.init(name: "internal-param", context: .query, schema: .string),
]
)
let op = OpenAPI.Operation(responses: [:])
let pathItem = OpenAPI.PathItem(
summary: "summary",
Expand All @@ -480,11 +474,9 @@ extension PathItemTests {

print(pathItem.parameters.debugDescription)
print("------")
let context = MockLoad()
var loader = ExternalLoader(components: components, context: context)
let x = try await pathItem.externallyDereferenced(with: &loader)
let (x, loaderComponents) = try await pathItem.externallyDereferenced(with: MockLoad.self)
print(x.parameters.debugDescription)
print("=======")
print(loader.components.parameters)
print(loaderComponents.parameters)
}
}

0 comments on commit 7863815

Please sign in to comment.