diff --git a/modules/openapi-generator/src/main/resources/swift6/libraries/urlsession/URLSessionImplementations.mustache b/modules/openapi-generator/src/main/resources/swift6/libraries/urlsession/URLSessionImplementations.mustache index 996ee57a561..ef1a0bbc9f4 100644 --- a/modules/openapi-generator/src/main/resources/swift6/libraries/urlsession/URLSessionImplementations.mustache +++ b/modules/openapi-generator/src/main/resources/swift6/libraries/urlsession/URLSessionImplementations.mustache @@ -52,8 +52,6 @@ extension URLSessionDataTask: URLSessionDataTaskProtocol {} } } -{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} typealias {{projectName}}APIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var taskDidReceiveChallenge: {{projectName}}APIChallengeHandler? - required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 95c724671b1..57044a6428e 100644 --- a/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ internal class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -internal typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } internal class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - internal var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required internal init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ internal class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendab self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ internal class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendab private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } } diff --git a/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 1a5f286eaf0..9996db3349a 100644 --- a/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory { } } -public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?)) - fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { private init() { defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil) @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable { // Store the URLSession to retain its reference let defaultURLSession: URLSession - // Store current taskDidReceiveChallenge for every URLSessionTask - var challengeHandlerStore = SynchronizedDictionary() - // Store current URLCredential for every URLSessionTask var credentialStore = SynchronizedDictionary() } open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { - /** - May be assigned if you want to control the authentication challenges. - */ - public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler? - required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) { super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient) } @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { self.onProgressReady?(dataTask.progress) - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential self.requestTask.set(task: dataTask) @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder: RequestBuilder, @unchecked Sendable { private func cleanupRequest() { if let task = requestTask.get() { - URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil } } @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate { var credential: URLCredential? - if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] { - (disposition, credential) = taskDidReceiveChallenge(session, task, challenge) + if challenge.previousFailureCount > 0 { + disposition = .rejectProtectionSpace } else { - if challenge.previousFailureCount > 0 { - disposition = .rejectProtectionSpace - } else { - credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) + credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace) - if credential != nil { - disposition = .useCredential - } + if credential != nil { + disposition = .useCredential } }