-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from nexon/bugfix/294-dereferencing-callbacks
Bugfix/294 dereferencing callbacks
- Loading branch information
Showing
8 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Sources/OpenAPIKit/Utility/OrderedDictionry+LocallyDereferenceable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// OrderedDictionry+LocallyDereferenceable.swift | ||
// | ||
// | ||
// Created by Alberto Lagos on 11-09-23. | ||
// | ||
|
||
import OpenAPIKitCore | ||
import Foundation | ||
|
||
/// A Swift extension for dereferencing an `OrderedDictionary` conforming to the `LocallyDereferenceable` protocol. | ||
/// | ||
/// - Parameters: | ||
/// - components: The OpenAPI components containing definitions. | ||
/// - references: A set of references to track dereferenced items. | ||
/// - name: The name of the component from which the dereferencing is initiated. | ||
/// | ||
/// - Returns: A dereferenced `OrderedDictionary` containing keys and values of dereferenced types. | ||
/// | ||
/// - Throws: An error if dereferencing fails for any element. | ||
extension OrderedDictionary: LocallyDereferenceable where Key: LocallyDereferenceable, Key.DereferencedSelf: Hashable, Value: LocallyDereferenceable { | ||
|
||
public func _dereferenced(in components: OpenAPI.Components, | ||
following references: Set<AnyHashable>, | ||
dereferencedFromComponentNamed name: String?) throws -> OpenAPIKitCore.OrderedDictionary<Key.DereferencedSelf, Value.DereferencedSelf> { | ||
|
||
try reduce(into: OrderedDictionary<Key.DereferencedSelf, Value.DereferencedSelf>()) { result, element in | ||
let key = try element.key._dereferenced(in: components, following: references, dereferencedFromComponentNamed: nil) | ||
|
||
let value = try element.value._dereferenced(in: components, following: references, dereferencedFromComponentNamed: nil) | ||
result[key] = value | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Sources/OpenAPIKit30/Utility/OrderedDictionry+LocallyDereferenceable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// OrderedDictionry+LocallyDereferenceable.swift | ||
// | ||
// | ||
// Created by Alberto Lagos on 11-09-23. | ||
// | ||
|
||
import OpenAPIKitCore | ||
import Foundation | ||
|
||
/// A Swift extension for dereferencing an `OrderedDictionary` conforming to the `LocallyDereferenceable` protocol. | ||
/// | ||
/// - Parameters: | ||
/// - components: The OpenAPI components containing definitions. | ||
/// - references: A set of references to track dereferenced items. | ||
/// - name: The name of the component from which the dereferencing is initiated. | ||
/// | ||
/// - Returns: A dereferenced `OrderedDictionary` containing keys and values of dereferenced types. | ||
/// | ||
/// - Throws: An error if dereferencing fails for any element. | ||
extension OrderedDictionary: LocallyDereferenceable where Key: LocallyDereferenceable, Key.DereferencedSelf: Hashable, Value: LocallyDereferenceable { | ||
|
||
public func _dereferenced(in components: OpenAPI.Components, | ||
following references: Set<AnyHashable>, | ||
dereferencedFromComponentNamed name: String?) throws -> OpenAPIKitCore.OrderedDictionary<Key.DereferencedSelf, Value.DereferencedSelf> { | ||
|
||
try reduce(into: OrderedDictionary<Key.DereferencedSelf, Value.DereferencedSelf>()) { result, element in | ||
let key = try element.key._dereferenced(in: components, following: references, dereferencedFromComponentNamed: nil) | ||
|
||
let value = try element.value._dereferenced(in: components, following: references, dereferencedFromComponentNamed: nil) | ||
result[key] = value | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters