Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Foundation{{#useVapor}}
import Vapor{{/useVapor}}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct APIHelper {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func rejectNil(_ source: [String: Any?]) -> [String: Any]? {
let destination = source.reduce(into: [String: Any]()) { result, item in
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func rejectNil(_ source: [String: (any Sendable)?]) -> [String: any Sendable]? {
let destination = source.reduce(into: [String: any Sendable]()) { result, item in
if let value = item.value {
result[item.key] = value
}
Expand All @@ -21,7 +21,7 @@ import Vapor{{/useVapor}}
return destination
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func rejectNilHeaders(_ source: [String: (any Sendable)?]) -> [String: String] {
return source.reduce(into: [String: String]()) { result, item in
if let collection = item.value as? [Any?] {
result[item.key] = collection
Expand All @@ -33,12 +33,12 @@ import Vapor{{/useVapor}}
}
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func convertBoolToString(_ source: [String: any Sendable]?) -> [String: any Sendable]? {
guard let source = source else {
return nil
}

return source.reduce(into: [String: Any]()) { result, item in
return source.reduce(into: [String: any Sendable]()) { result, item in
switch item.value {
case let x as Bool:
result[item.key] = x.description
Expand Down Expand Up @@ -100,7 +100,7 @@ import Vapor{{/useVapor}}
/// maps all values from source to query parameters
///
/// collection values are always exploded
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func mapValuesToQueryItems(_ source: [String: (any Sendable)?]) -> [URLQueryItem]? {
let destination = source.filter { $0.value != nil }.reduce(into: [URLQueryItem]()) { result, item in
if let collection = item.value as? [Any?] {
collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import Alamofire{{/useAlamofire}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class RequestBuilder<T>: @unchecked Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var credential: URLCredential?
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var headers: [String: String]
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let parameters: [String: Any]?
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let parameters: [String: any Sendable]?
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let method: String
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let URLString: String
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let requestTask: RequestTask = RequestTask()
Expand All @@ -95,7 +95,7 @@ import Alamofire{{/useAlamofire}}
/// Optional block to obtain a reference to the request's progress instance when available.
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var onProgressReady: ((Progress) -> Void)?

required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, apiConfiguration: {{projectName}}APIConfiguration = {{projectName}}APIConfiguration.shared) {
required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: any Sendable]?, headers: [String: String] = [:], requiresAuthentication: Bool, apiConfiguration: {{projectName}}APIConfiguration = {{projectName}}APIConfiguration.shared) {
self.method = method
self.URLString = URLString
self.parameters = parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{#useAlamofire}}
# TODO: Alamofire versions 5.10.0 and above are not currently supported. If you need a newer version, please consider submitting a Pull Request with the required changes.
github "Alamofire/Alamofire" = 5.9.1{{/useAlamofire}}{{#usePromiseKit}}
github "Alamofire/Alamofire" = 5.10.2{{/useAlamofire}}{{#usePromiseKit}}
github "mxcl/PromiseKit" ~> 8.1{{/usePromiseKit}}{{#useRxSwift}}
github "ReactiveX/RxSwift" ~> 6.8{{/useRxSwift}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,98 +11,74 @@ import FoundationNetworking
@preconcurrency import PromiseKit{{/usePromiseKit}}{{#useVapor}}
import Vapor{{/useVapor}}{{^useVapor}}

extension Bool: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension Float: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension Int: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension Int32: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension Int64: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension Double: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension Decimal: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension String: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}

extension URL: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
}
extension Bool: QueryStringEncodable {}
extension Float: QueryStringEncodable {}
extension Int: QueryStringEncodable {}
extension Int32: QueryStringEncodable {}
extension Int64: QueryStringEncodable {}
extension Double: QueryStringEncodable {}
extension Decimal: QueryStringEncodable {}
extension String: QueryStringEncodable {}
extension URL: QueryStringEncodable {}
extension UUID: QueryStringEncodable {}

extension UUID: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
extension QueryStringEncodable {
@_disfavoredOverload
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: self) }
}

extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any { return self.rawValue }
extension RawRepresentable where RawValue: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String { String(describing: rawValue) }
}

private func encodeIfPossible<T>(_ object: T, codableHelper: CodableHelper) -> Any {
if let encodableObject = object as? JSONEncodable {
return encodableObject.encodeToJSON(codableHelper: codableHelper)
private func encodeIfPossible<T>(_ object: T, codableHelper: CodableHelper) -> String {
if let encodableObject = object as? QueryStringEncodable {
return encodableObject.encodeToQueryString(codableHelper: codableHelper)
} else {
return object
return String(describing: object)
}
}

extension Array: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
extension Array {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
return self.map { encodeIfPossible($0, codableHelper: codableHelper) }
}
}

extension Set: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
return Array(self).encodeToJSON(codableHelper: codableHelper)
extension Set {
func encodeToQueryString(codableHelper: CodableHelper) -> [String] {
return Array(self).encodeToQueryString(codableHelper: codableHelper)
}
}

extension Dictionary: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
var dictionary = [AnyHashable: Any]()
extension Dictionary {
func encodeToQueryString(codableHelper: CodableHelper) -> [Key: String] {
var dictionary = [Key: String]()
for (key, value) in self {
dictionary[key] = encodeIfPossible(value, codableHelper: codableHelper)
}
return dictionary
}
}

extension Data: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
extension Data: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
return self.base64EncodedString(options: Data.Base64EncodingOptions())
}
}

extension Date: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
extension Date: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
return codableHelper.dateFormatter.string(from: self)
}
}

extension JSONEncodable where Self: Encodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
extension QueryStringEncodable where Self: Encodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
guard let data = try? codableHelper.jsonEncoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON(codableHelper: codableHelper)
return data.encodeToQueryString(codableHelper: codableHelper)
}
}{{/useVapor}}{{#generateModelAdditionalProperties}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import FoundationNetworking
#endif

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct JSONDataEncoding {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct JSONDataEncoding: Sendable {

// MARK: Properties

Expand All @@ -27,8 +27,8 @@ import FoundationNetworking
/// - throws: An `Error` if the encoding process encounters an error.
///
/// - returns: The encoded request.
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) -> URLRequest {
var urlRequest = urlRequest
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func encode(request: URLRequest, with parameters: [String: any Sendable]?) -> URLRequest {
var urlRequest = request

guard let jsonData = parameters?[JSONDataEncoding.jsonDataKey] as? Data, !jsonData.isEmpty else {
return urlRequest
Expand All @@ -43,10 +43,10 @@ import FoundationNetworking
return urlRequest
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func encodingParameters(jsonData: Data?) -> [String: Any]? {
var returnedParams: [String: Any]?
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func encodingParameters(jsonData: Data?) -> [String: any Sendable]? {
var returnedParams: [String: any Sendable]?
if let jsonData = jsonData, !jsonData.isEmpty {
var params: [String: Any] = [:]
var params: [String: any Sendable] = [:]
params[jsonDataKey] = jsonData
returnedParams = params
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Foundation

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class JSONEncodingHelper {

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encodingParameters<T: Encodable>(forEncodableObject encodableObj: T?, codableHelper: CodableHelper) -> [String: Any]? {
var params: [String: Any]?
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encodingParameters<T: Encodable>(forEncodableObject encodableObj: T?, codableHelper: CodableHelper) -> [String: any Sendable]? {
var params: [String: any Sendable]?

// Encode the Encodable object
if let encodableObj = encodableObj {
Expand All @@ -26,8 +26,8 @@ import Foundation
return params
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encodingParameters(forEncodableObject encodableObj: Any?, codableHelper: CodableHelper) -> [String: Any]? {
var params: [String: Any]?
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encodingParameters(forEncodableObject encodableObj: Any?, codableHelper: CodableHelper) -> [String: any Sendable]? {
var params: [String: any Sendable]?

if let encodableObj = encodableObj {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import FoundationNetworking
#endif{{#useAlamofire}}
import Alamofire{{/useAlamofire}}

protocol JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any
protocol QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String
}

/// An enum where the last case value can be used as a default catch-all.
Expand Down Expand Up @@ -119,9 +119,9 @@ extension Response : Sendable where T : Sendable {}{{#useAlamofire}}
/// Type-erased ResponseSerializer
///
/// This is needed in order to use `ResponseSerializer` as a Type in `Configuration`. Obsolete with `any` keyword in Swift >= 5.7
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct AnyResponseSerializer<T>: ResponseSerializer {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct AnyResponseSerializer<T: Sendable>: ResponseSerializer {

let _serialize: (URLRequest?, HTTPURLResponse?, Data?, Error?) throws -> T
let _serialize: @Sendable (URLRequest?, HTTPURLResponse?, Data?, Error?) throws -> T

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init<V: ResponseSerializer>(_ delegatee: V) where V.SerializedObject == T {
_serialize = delegatee.serialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ import Foundation
}
}

extension OpenAPIDateWithoutTime: JSONEncodable {
func encodeToJSON(codableHelper: CodableHelper) -> Any {
extension OpenAPIDateWithoutTime: QueryStringEncodable {
func encodeToQueryString(codableHelper: CodableHelper) -> String {
return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
{{#useAlamofire}}
// TODO: Alamofire versions 5.10.0 and above are not currently supported. If you need a newer version, please consider submitting a Pull Request with the required changes.
.package(url: "https://github.com/Alamofire/Alamofire", exact: "5.9.1"),
.package(url: "https://github.com/Alamofire/Alamofire", exact: "5.10.2"),
{{/useAlamofire}}
{{#usePromiseKit}}
.package(url: "https://github.com/mxcl/PromiseKit", .upToNextMajor(from: "8.1.2")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Pod::Spec.new do |s|
{{/podDocumentationURL}}
s.source_files = '{{swiftPackagePath}}{{^swiftPackagePath}}{{#useSPMFileStructure}}Sources/{{projectName}}{{/useSPMFileStructure}}{{^useSPMFileStructure}}{{projectName}}/Classes{{/useSPMFileStructure}}{{/swiftPackagePath}}/**/*.swift'
{{#useAlamofire}}
# TODO: Alamofire versions 5.10.0 and above are not currently supported. If you need a newer version, please consider submitting a Pull Request with the required changes.
s.dependency 'Alamofire', '5.9.1'
s.dependency 'Alamofire', '5.10.2'
{{/useAlamofire}}
{{#usePromiseKit}}
s.dependency 'PromiseKit/CorePromise', '~> 8.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"{{baseName}}": {{#isQueryParam}}(wrappedValue: {{/isQueryParam}}{{paramName}}{{^required}}?{{/required}}.encodeToJSON(codableHelper: apiConfiguration.codableHelper){{#isQueryParam}}, isExplode: {{isExplode}}){{/isQueryParam}}
"{{baseName}}": {{#isQueryParam}}(wrappedValue: {{/isQueryParam}}{{paramName}}{{^required}}?{{/required}}.encodeToQueryString(codableHelper: apiConfiguration.codableHelper){{#isQueryParam}}, isExplode: {{isExplode}}){{/isQueryParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ extension {{projectName}}API {
{{/bodyParam}}
{{^bodyParam}}
{{#hasFormParams}}
let localVariableFormParams: [String: Any?] = [
let localVariableFormParams: [String: (any Sendable)?] = [
{{#formParams}}
{{> _param}},
{{/formParams}}
Expand All @@ -305,7 +305,7 @@ extension {{projectName}}API {
let localVariableParameters = APIHelper.convertBoolToString(localVariableNonNullParameters)
{{/hasFormParams}}
{{^hasFormParams}}
let localVariableParameters: [String: Any]? = nil
let localVariableParameters: [String: any Sendable]? = nil
{{/hasFormParams}}
{{/bodyParam}}{{#hasQueryParams}}
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
Expand All @@ -316,7 +316,7 @@ extension {{projectName}}API {
]){{/hasQueryParams}}{{^hasQueryParams}}
let localVariableUrlComponents = URLComponents(string: localVariableURLString){{/hasQueryParams}}

let localVariableNillableHeaders: [String: Any?] = [{{^headerParams}}{{^hasFormParams}}{{^hasConsumes}}
let localVariableNillableHeaders: [String: (any Sendable)?] = [{{^headerParams}}{{^hasFormParams}}{{^hasConsumes}}
:{{/hasConsumes}}{{/hasFormParams}}{{/headerParams}}{{#hasFormParams}}
"Content-Type": {{^consumes}}"multipart/form-data"{{/consumes}}{{#consumes.0}}"{{{mediaType}}}"{{/consumes.0}},{{/hasFormParams}}{{^hasFormParams}}{{#hasConsumes}}
"Content-Type": {{#consumes.0}}"{{{mediaType}}}"{{/consumes.0}},{{/hasConsumes}}{{/hasFormParams}}{{#headerParams}}
Expand Down
Loading
Loading