Skip to content

Commit

Permalink
fill in some actual external dereferencing tests for json references
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Apr 18, 2024
1 parent 3fc8750 commit 47af348
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Tests/OpenAPIKitTests/JSONReferenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,32 @@ extension JSONReferenceTests {

// MARK: - External Dereferencing
extension JSONReferenceTests {

func test_externalDerefNoFragment() async throws {
let reference: JSONReference<JSONSchema> = .external(.init(string: "./schema.json")!)

let (newReference, components) = try await reference.externallyDereferenced(with: SchemaLoader.self)

XCTAssertEqual(newReference, .component(named: "__schema_json"))
XCTAssertEqual(components, .init(schemas: ["__schema_json": .string]))
}

func test_externalDerefFragment() async throws {
let reference: JSONReference<JSONSchema> = .external(.init(string: "./schema.json#/test")!)

let (newReference, components) = try await reference.externallyDereferenced(with: SchemaLoader.self)

XCTAssertEqual(newReference, .component(named: "__schema_json__test"))
XCTAssertEqual(components, .init(schemas: ["__schema_json__test": .string]))
}

func test_externalDerefExternalComponents() async throws {
let reference: JSONReference<JSONSchema> = .external(.init(string: "./schema.json#/components/schemas/test")!)

let (newReference, components) = try await reference.externallyDereferenced(with: SchemaLoader.self)

XCTAssertEqual(newReference, .component(named: "__schema_json__components_schemas_test"))
XCTAssertEqual(components, .init(schemas: ["__schema_json__components_schemas_test": .string]))
}
}

// MARK: - Test Types
Expand All @@ -394,6 +419,10 @@ extension JSONReferenceTests {
}

static func componentKey<T>(type: T.Type, at url: URL) throws -> OpenAPI.ComponentKey {
return try .forceInit(rawValue: url.absoluteString
.replacingOccurrences(of: "/", with: "_")
.replacingOccurrences(of: "#", with: "_")
.replacingOccurrences(of: ".", with: "_"))
}
}
}

0 comments on commit 47af348

Please sign in to comment.