Skip to content

Commit

Permalink
a bit more work towards external dereferencing implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Apr 8, 2024
1 parent 2508f85 commit 2b90c7c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
26 changes: 23 additions & 3 deletions Sources/OpenAPIKit/Operation/DereferencedOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,28 @@ extension OpenAPI.Operation: LocallyDereferenceable {

extension OpenAPI.Operation: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
// TODO: externally dereference security, responses, requestBody, and parameters
#warning("externally dereference security, responses, requestBody, and parameters")
return (self, .init())
let oldParameters = parameters
let oldRequestBody = requestBody
let oldResponses = responses

async let (newParameters, c1) = oldParameters.externallyDereferenced(with: loader)
async let (newRequestBody, c2) = oldRequestBody.externallyDereferenced(with: loader)
async let (newResponses, c3) = oldResponses.externallyDereferenced(with: loader)
// let (newCallbacks, c4) = try await callbacks.externallyDereferenced(with: loader)
// let (newSecurtiy, c5) = try await security.externallyDereferenced(with: loader)
// let (newServers, c6) = try await servers.externallyDereferenced(with: loader)

var newOperation = self
var newComponents = try await c1

newOperation.parameters = try await newParameters
newOperation.requestBody = try await newRequestBody
try await newComponents.merge(c2)
newOperation.responses = try await newResponses
try await newComponents.merge(c3)

// TODO: externally dereference servers, callbacks, and security
#warning("externally dereference servers, callbacks, and security")
return (newOperation, newComponents)
}
}
27 changes: 23 additions & 4 deletions Sources/OpenAPIKit/Parameter/DereferencedParameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,28 @@ extension OpenAPI.Parameter: LocallyDereferenceable {

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

// TODO: externallyDerefence the schemaOrContent
#warning("need to externally dereference the schemaOrContent here")
return (self, .init())

// if not for a Swift bug, this whole function would just be the
// next line:
// let (newSchemaOrContent, components) = try await schemaOrContent.externallyDereferenced(with: loader)

let newSchemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>
let newComponents: OpenAPI.Components

switch schemaOrContent {
case .a(let schemaContext):
let (context, components) = try await schemaContext.externallyDereferenced(with: loader)
newSchemaOrContent = .a(context)
newComponents = components
case .b(let contentMap):
let (map, components) = try await contentMap.externallyDereferenced(with: loader)
newSchemaOrContent = .b(map)
newComponents = components
}

var newParameter = self
newParameter.schemaOrContent = newSchemaOrContent

return (newParameter, newComponents)
}
}
9 changes: 6 additions & 3 deletions Sources/OpenAPIKit/Request/DereferencedRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ extension OpenAPI.Request: LocallyDereferenceable {

extension OpenAPI.Request: ExternallyDereferenceable {
public func externallyDereferenced<Context: ExternalLoaderContext>(with loader: Context.Type) async throws -> (Self, OpenAPI.Components) {
// TODO: externally dereference the content
#warning("externally dereference the content")
return (self, .init())
var newRequest = self

let (newContent, components) = try await content.externallyDereferenced(with: loader)

newRequest.content = newContent
return (newRequest, components)
}
}

0 comments on commit 2b90c7c

Please sign in to comment.