Skip to content

Commit

Permalink
rename ExternalLoaderContext to ExternalLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Apr 18, 2024
1 parent 6d6be19 commit 3fc8750
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Callbacks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension OpenAPI.CallbackURL: LocallyDereferenceable {
}

extension OpenAPI.CallbackURL: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
return (self, .init())
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Components Object/Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ extension OpenAPI.Components {
}

extension OpenAPI.Components {
internal mutating func externallyDereference<Context: ExternalLoaderContext>(in context: Context.Type) async throws {
internal mutating func externallyDereference<Context: ExternalLoader>(in context: Context.Type) async throws {
let oldSchemas = schemas
let oldResponses = responses
let oldParameters = parameters
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Content/DereferencedContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension OpenAPI.Content: LocallyDereferenceable {
}

extension OpenAPI.Content: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let oldSchema = schema

async let (newSchema, c1) = oldSchema.externallyDereferenced(with: loader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension OpenAPI.Content.Encoding: LocallyDereferenceable {
}

extension OpenAPI.Content.Encoding: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let newHeaders: OpenAPI.Header.Map?
let newComponents: OpenAPI.Components

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Document/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ extension OpenAPI.Document {
return try DereferencedDocument(self)
}

public mutating func externallyDereference<Context: ExternalLoaderContext>(in context: Context.Type) async throws {
public mutating func externallyDereference<Context: ExternalLoader>(in context: Context.Type) async throws {
let oldPaths = paths
let oldWebhooks = webhooks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OpenAPIKitCore
// MARK: - ExternallyDereferenceable
extension Either: ExternallyDereferenceable where A: ExternallyDereferenceable, B: ExternallyDereferenceable {

public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
switch self {
case .a(let a):
let (newA, components) = try await a.externallyDereferenced(with: loader)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extension OpenAPI.Example: LocallyDereferenceable {
}

extension OpenAPI.Example: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
return (self, .init())
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/OpenAPIKit/ExternalLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import OpenAPIKitCore
import Foundation

/// An `ExternalLoaderContext` enables `OpenAPIKit` to load external references
/// An `ExternalLoader` enables `OpenAPIKit` to load external references
/// without knowing the details of what decoder is being used or how new internal
/// references should be named.
public protocol ExternalLoaderContext {
public protocol ExternalLoader {
/// Load the given URL and decode it as Type `T`. All Types `T` are `Decodable`, so
/// the only real responsibility of a `load` function is to locate and load the given
/// `URL` and pass its `Data` or `String` (depending on the decoder) to an appropriate
Expand All @@ -30,5 +30,5 @@ public protocol ExternalLoaderContext {
}

public protocol ExternallyDereferenceable {
func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components)
func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components)
}
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Header/DereferencedHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension OpenAPI.Header: LocallyDereferenceable {
}

extension OpenAPI.Header: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {

// if not for a Swift bug, this whole next bit would just be the
// next line:
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenAPIKit/JSONReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ extension JSONReference: LocallyDereferenceable where ReferenceType: LocallyDere
}

extension JSONReference: ExternallyDereferenceable where ReferenceType: ExternallyDereferenceable & Decodable & Equatable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
switch self {
case .internal(let ref):
return (.internal(ref), .init())
Expand Down Expand Up @@ -580,7 +580,7 @@ extension OpenAPI.Reference: LocallyDereferenceable where ReferenceType: Locally
}

extension OpenAPI.Reference: ExternallyDereferenceable where ReferenceType: ExternallyDereferenceable & Decodable & Equatable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let (newRef, components) = try await jsonReference.externallyDereferenced(with: loader)
return (.init(newRef), components)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Link.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ extension OpenAPI.Link: LocallyDereferenceable {
}

extension OpenAPI.Link: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let (newServer, newComponents) = try await server.externallyDereferenced(with: loader)

var newLink = self
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Operation/DereferencedOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension OpenAPI.Operation: LocallyDereferenceable {
}

extension OpenAPI.Operation: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let oldParameters = parameters
let oldRequestBody = requestBody
let oldResponses = responses
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Parameter/DereferencedParameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension OpenAPI.Parameter: LocallyDereferenceable {
}

extension OpenAPI.Parameter: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {

// if not for a Swift bug, this whole function would just be the
// next line:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension OpenAPI.Parameter.SchemaContext: LocallyDereferenceable {
}

extension OpenAPI.Parameter.SchemaContext: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let oldSchema = schema

async let (newSchema, c1) = oldSchema.externallyDereferenced(with: loader)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Path Item/DereferencedPathItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension OpenAPI.PathItem: LocallyDereferenceable {
}

extension OpenAPI.PathItem: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let oldParameters = parameters
let oldServers = servers
let oldGet = get
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Request/DereferencedRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension OpenAPI.Request: LocallyDereferenceable {
}

extension OpenAPI.Request: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
var newRequest = self

let (newContent, components) = try await content.externallyDereferenced(with: loader)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Response/DereferencedResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension OpenAPI.Response: LocallyDereferenceable {
}

extension OpenAPI.Response: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let oldContent = content
let oldLinks = links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ extension JSONSchema: LocallyDereferenceable {
}

extension JSONSchema: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
let newSchema: JSONSchema
let newComponents: OpenAPI.Components

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Security/SecurityScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ extension OpenAPI.SecurityScheme: LocallyDereferenceable {
}

extension OpenAPI.SecurityScheme: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
return (self, .init())
}
}
2 changes: 1 addition & 1 deletion Sources/OpenAPIKit/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ extension OpenAPI.Server.Variable {
}

extension OpenAPI.Server: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
return (self, .init())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import OpenAPIKitCore

extension Array where Element: ExternallyDereferenceable {

public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
try await withThrowingTaskGroup(of: (Element, OpenAPI.Components).self) { group in
for elem in self {
group.addTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import OpenAPIKitCore

extension Dictionary where Value: ExternallyDereferenceable {

public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
try await withThrowingTaskGroup(of: (Key, Value, OpenAPI.Components).self) { group in
for (key, value) in self {
group.addTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import OpenAPIKitCore

extension Optional where Wrapped: ExternallyDereferenceable {

public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
guard let wrapped = self else { return (nil, .init()) }
return try await wrapped.externallyDereferenced(with: loader)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import OpenAPIKitCore

extension OrderedDictionary where Value: ExternallyDereferenceable {

public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
public func externallyDereferenced<Context: ExternalLoader>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
try await withThrowingTaskGroup(of: (Key, Value, OpenAPI.Components).self) { group in
for (key, value) in self {
group.addTask {
Expand Down
2 changes: 1 addition & 1 deletion Tests/OpenAPIKitTests/Document/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ extension DocumentTests {

/// An example of implementing a loader context for loading external references
/// into an OpenAPI document.
struct ExampleLoaderContext: ExternalLoaderContext {
struct ExampleLoaderContext: ExternalLoader {
static func load<T>(_ url: URL) async throws -> T where T : Decodable {
// load data from file, perhaps. we will just mock that up for the example:
let data = await mockParameterData(url)
Expand Down
14 changes: 14 additions & 0 deletions Tests/OpenAPIKitTests/JSONReferenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,23 @@ extension JSONReferenceTests {
}
}

// MARK: - External Dereferencing
extension JSONReferenceTests {

}

// MARK: - Test Types
extension JSONReferenceTests {
struct ReferenceWrapper: Codable, Equatable {
let reference: JSONReference<JSONSchema>
}

struct SchemaLoader: ExternalLoader {
static func load<T>(_ url: URL) -> T where T: Decodable {
return JSONSchema.string as! T
}

static func componentKey<T>(type: T.Type, at url: URL) throws -> OpenAPI.ComponentKey {
}
}
}
2 changes: 1 addition & 1 deletion 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 {
struct MockLoad: ExternalLoader {
static func componentKey<T>(type: T.Type, at url: URL) throws -> OpenAPI.ComponentKey {
let urlString = url.pathComponents.dropFirst().joined(separator: "_").replacingOccurrences(of: ".", with: "_")

Expand Down

0 comments on commit 3fc8750

Please sign in to comment.