Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation{{#useVapor}}
import Vapor{{/useVapor}}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct APIHelper {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct APIHelper: Sendable {
{{#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 {
Expand Down
22 changes: 18 additions & 4 deletions modules/openapi-generator/src/main/resources/swift6/APIs.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import Alamofire{{/useAlamofire}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static let shared = {{projectName}}APIConfiguration()
}{{^useVapor}}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class RequestBuilder<T>: @unchecked Sendable, Identifiable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class RequestBuilder<T: Sendable>: @unchecked Sendable, Identifiable {
{{#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 Sendable]?
Expand Down Expand Up @@ -119,9 +119,24 @@ import Alamofire{{/useAlamofire}}
}

{{#useAsyncAwait}}
#if compiler(>=6.2)
@concurrent
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute() async throws(ErrorResponse) -> Response<T> {
try await _execute()
}
#else
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute() async throws(ErrorResponse) -> Response<T> {
try await _execute()
}
#endif

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
private func _execute() async throws(ErrorResponse) -> Response<T> {
do {
let requestTask = self.requestTask
return try await withTaskCancellationHandler {
Expand All @@ -135,7 +150,6 @@ import Alamofire{{/useAlamofire}}
self.execute { result in
switch result {
case let .success(response):
nonisolated(unsafe) let response = response
continuation.resume(returning: response)
case let .failure(error):
continuation.resume(throwing: error)
Expand All @@ -153,7 +167,7 @@ import Alamofire{{/useAlamofire}}
}
}
}

{{/useAsyncAwait}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func addHeader(name: String, value: String) -> Self {
if !value.isEmpty {
Expand All @@ -167,7 +181,7 @@ import Alamofire{{/useAlamofire}}
}
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} protocol RequestBuilderFactory {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} protocol RequestBuilderFactory: Sendable {
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
}{{/useVapor}}
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ extension NullEncodable: Codable where Wrapped: Codable {
}
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse: Error, @unchecked Sendable {
case error(Int, Data?, URLResponse?, Error)
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum DownloadException: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum DownloadException: Error, Sendable {
case responseDataMissing
case responseFailed
case requestMissing
case requestMissingPath
case requestMissingURL
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum DecodableRequestBuilderError: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum DecodableRequestBuilderError: Error, @unchecked Sendable {
case emptyDataResponse
case nilHTTPResponse
case unsuccessfulHTTPStatusCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ extension NumericRule: Sendable where T: Sendable {}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var uniqueItems: Bool
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum StringValidationErrorKind: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum StringValidationErrorKind: Error, Sendable {
case minLength, maxLength, pattern
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum NumericValidationErrorKind: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum NumericValidationErrorKind: Error, Sendable {
case minimum, maximum, multipleOf
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ArrayValidationErrorKind: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ArrayValidationErrorKind: Error, Sendable {
case minItems, maxItems, uniqueItems
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct ValidationError<T: Error & Hashable>: Error {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct ValidationError<T: Error & Hashable & Sendable>: Error, Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} fileprivate(set) var kinds: Set<T>
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct Validator {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct Validator: Sendable {
/// Validate a string against a rule.
/// - Parameter string: The String you wish to validate.
/// - Parameter rule: The StringRule you wish to use for validation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation
import Alamofire

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class AlamofireRequestBuilderFactory: RequestBuilderFactory {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} final class AlamofireRequestBuilderFactory: RequestBuilderFactory, Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init() {}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type {
Expand All @@ -27,7 +27,7 @@ fileprivate class AlamofireRequestBuilderConfiguration: @unchecked Sendable {
var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class AlamofireRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class AlamofireRequestBuilder<T: Sendable>: RequestBuilder<T>, @unchecked Sendable {
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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, apiConfiguration: apiConfiguration)
}
Expand Down Expand Up @@ -255,7 +255,7 @@ fileprivate class AlamofireRequestBuilderConfiguration: @unchecked Sendable {

}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class AlamofireDecodableRequestBuilder<T: Decodable>: AlamofireRequestBuilder<T>, @unchecked Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class AlamofireDecodableRequestBuilder<T: Decodable & Sendable>: AlamofireRequestBuilder<T>, @unchecked Sendable {

override fileprivate func processRequest(request: DataRequest, managerId: String, completion: @Sendable @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) {
if let credential = self.credential {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension URLSession: URLSessionProtocol {

extension URLSessionDataTask: URLSessionDataTaskProtocol {}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class URLSessionRequestBuilderFactory: RequestBuilderFactory {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} final class URLSessionRequestBuilderFactory: RequestBuilderFactory, Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init() {}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type {
Expand Down Expand Up @@ -69,7 +69,7 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionRequestBuilder<T: Sendable>: RequestBuilder<T>, @unchecked Sendable {

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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, apiConfiguration: apiConfiguration)
Expand Down Expand Up @@ -319,7 +319,7 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {

}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionDecodableRequestBuilder<T: Decodable>: URLSessionRequestBuilder<T>, @unchecked Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionDecodableRequestBuilder<T: Decodable & Sendable>: URLSessionRequestBuilder<T>, @unchecked Sendable {
override fileprivate func processRequestResponse(urlRequest: URLRequest, data: Data?, httpResponse: HTTPURLResponse, error: Error?, completion: @Sendable @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) {

switch T.self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}@unchecked Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{/objcCompatible}}{{#objcCompatible}}@objcMembers {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable {
{{/objcCompatible}}{{#objcCompatible}}@objcMembers {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} final class {{classname}}: NSObject, Codable, @unchecked Sendable {
{{/objcCompatible}}

{{#allVars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

public struct APIHelper {
public struct APIHelper: Sendable {
public 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ open class PetstoreClientAPIConfiguration: @unchecked Sendable {
public static let shared = PetstoreClientAPIConfiguration()
}

open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
open class RequestBuilder<T: Sendable>: @unchecked Sendable, Identifiable {
public var credential: URLCredential?
public var headers: [String: String]
public let parameters: [String: any Sendable]?
Expand Down Expand Up @@ -109,7 +109,7 @@ open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
}
}

public protocol RequestBuilderFactory {
public protocol RequestBuilderFactory: Sendable {
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation
import Alamofire

public class AlamofireRequestBuilderFactory: RequestBuilderFactory {
public final class AlamofireRequestBuilderFactory: RequestBuilderFactory, Sendable {
public init() {}

public func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type {
Expand All @@ -27,7 +27,7 @@ fileprivate class AlamofireRequestBuilderConfiguration: @unchecked Sendable {
var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
}

open class AlamofireRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
open class AlamofireRequestBuilder<T: Sendable>: RequestBuilder<T>, @unchecked Sendable {
required public init(method: String, URLString: String, parameters: [String: any Sendable]?, headers: [String: String] = [:], requiresAuthentication: Bool, apiConfiguration: PetstoreClientAPIConfiguration = PetstoreClientAPIConfiguration.shared) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, apiConfiguration: apiConfiguration)
}
Expand Down Expand Up @@ -255,7 +255,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

}

open class AlamofireDecodableRequestBuilder<T: Decodable>: AlamofireRequestBuilder<T>, @unchecked Sendable {
open class AlamofireDecodableRequestBuilder<T: Decodable & Sendable>: AlamofireRequestBuilder<T>, @unchecked Sendable {

override fileprivate func processRequest(request: DataRequest, managerId: String, completion: @Sendable @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) {
if let credential = self.credential {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ extension NullEncodable: Codable where Wrapped: Codable {
}
}

public enum ErrorResponse: Error {
public enum ErrorResponse: Error, @unchecked Sendable {
case error(Int, Data?, URLResponse?, Error)
}

public enum DownloadException: Error {
public enum DownloadException: Error, Sendable {
case responseDataMissing
case responseFailed
case requestMissing
case requestMissingPath
case requestMissingURL
}

public enum DecodableRequestBuilderError: Error {
public enum DecodableRequestBuilderError: Error, @unchecked Sendable {
case emptyDataResponse
case nilHTTPResponse
case unsuccessfulHTTPStatusCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ public struct ArrayRule: Sendable {
public var uniqueItems: Bool
}

public enum StringValidationErrorKind: Error {
public enum StringValidationErrorKind: Error, Sendable {
case minLength, maxLength, pattern
}

public enum NumericValidationErrorKind: Error {
public enum NumericValidationErrorKind: Error, Sendable {
case minimum, maximum, multipleOf
}

public enum ArrayValidationErrorKind: Error {
public enum ArrayValidationErrorKind: Error, Sendable {
case minItems, maxItems, uniqueItems
}

public struct ValidationError<T: Error & Hashable>: Error {
public struct ValidationError<T: Error & Hashable & Sendable>: Error, Sendable {
public fileprivate(set) var kinds: Set<T>
}

public struct Validator {
public struct Validator: Sendable {
/// Validate a string against a rule.
/// - Parameter string: The String you wish to validate.
/// - Parameter rule: The StringRule you wish to use for validation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

public struct APIHelper {
public struct APIHelper: Sendable {
public 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ open class PetstoreClientAPIConfiguration: @unchecked Sendable {
public static let shared = PetstoreClientAPIConfiguration()
}

open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
open class RequestBuilder<T: Sendable>: @unchecked Sendable, Identifiable {
public var credential: URLCredential?
public var headers: [String: String]
public let parameters: [String: any Sendable]?
Expand Down Expand Up @@ -97,9 +97,24 @@ open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
return requestTask
}

#if compiler(>=6.2)
@concurrent
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
open func execute() async throws(ErrorResponse) -> Response<T> {
try await _execute()
}
#else
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
open func execute() async throws(ErrorResponse) -> Response<T> {
try await _execute()
}
#endif

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
private func _execute() async throws(ErrorResponse) -> Response<T> {
do {
let requestTask = self.requestTask
return try await withTaskCancellationHandler {
Expand All @@ -113,7 +128,6 @@ open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
self.execute { result in
switch result {
case let .success(response):
nonisolated(unsafe) let response = response
continuation.resume(returning: response)
case let .failure(error):
continuation.resume(throwing: error)
Expand All @@ -131,7 +145,7 @@ open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
}
}
}

public func addHeader(name: String, value: String) -> Self {
if !value.isEmpty {
headers[name] = value
Expand All @@ -144,7 +158,7 @@ open class RequestBuilder<T>: @unchecked Sendable, Identifiable {
}
}

public protocol RequestBuilderFactory {
public protocol RequestBuilderFactory: Sendable {
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
}
Loading
Loading