From 5f1f47d1568f9cbd9fab2b27715054736c85b5b3 Mon Sep 17 00:00:00 2001 From: leszek-s <1277962+leszek-s@users.noreply.github.com> Date: Tue, 19 Apr 2022 11:53:16 +0200 Subject: [PATCH] [swift5] Abstract away URLSession (#11651) (#12110) --- .../urlsession/URLSessionImplementations.mustache | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- .../PetstoreClient/URLSessionImplementations.swift | 10 ++++++++-- .../Classes/OpenAPIs/URLSessionImplementations.swift | 10 ++++++++-- 15 files changed, 120 insertions(+), 30 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache b/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache index e235cd37200..ab55655f3b0 100644 --- a/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ private var credentialStore = SynchronizedDictionary() May be overridden by a subclass if you want to control the URLSession configuration. */ - {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func createURLSession() -> URLSession { + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ private var credentialStore = SynchronizedDictionary() May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index 86beadcc71c..6195dbe996a 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +internal protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ internal class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - internal func createURLSession() -> URLSession { + internal func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ internal class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - internal func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + internal func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index ca22cb7e6e5..1d5288a137a 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -9,6 +9,12 @@ import Foundation import MobileCoreServices #endif +public protocol URLSessionProtocol { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +extension URLSession: URLSessionProtocol {} + class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { return URLSessionRequestBuilder.self @@ -57,7 +63,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLSession configuration. */ - open func createURLSession() -> URLSession { + open func createURLSession() -> URLSessionProtocol { return defaultURLSession } @@ -76,7 +82,7 @@ open class URLSessionRequestBuilder: RequestBuilder { May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession: URLSession, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL