... | ... | @@ -331,8 +331,7 @@ Please use `swift5` generator because Swift 4.x is deprecated. |
|
|
|
|
|
<details>
|
|
|
<summary>Then you subclass URLSessionRequestBuilder and URLSessionDecodableRequestBuilder </summary>
|
|
|
|
|
|
class BearerRequestBuilder<T>: URLSessionRequestBuilder<T> {
|
|
|
class BearerRequestBuilder<T>: URLSessionRequestBuilder<T> {
|
|
|
@discardableResult
|
|
|
override func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (Result<Response<T>, ErrorResponse>) -> Void) -> OpenApiRequestCancellable {
|
|
|
|
... | ... | @@ -378,9 +377,9 @@ class BearerRequestBuilder<T>: URLSessionRequestBuilder<T> { |
|
|
|
|
|
return requestCancellable
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class BearerDecodableRequestBuilder<T: Decodable>: URLSessionDecodableRequestBuilder<T> {
|
|
|
class BearerDecodableRequestBuilder<T: Decodable>: URLSessionDecodableRequestBuilder<T> {
|
|
|
@discardableResult
|
|
|
override func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (Result<Response<T>, ErrorResponse>) -> Void) -> OpenApiRequestCancellable {
|
|
|
// Before making the request, we can validate if we have a bearer token to be able to make a request
|
... | ... | @@ -425,9 +424,9 @@ class BearerDecodableRequestBuilder<T: Decodable>: URLSessionDecodableRequestBui |
|
|
|
|
|
return requestCancellable
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class BearerTokenHandler {
|
|
|
class BearerTokenHandler {
|
|
|
private static var bearerToken: String? = nil
|
|
|
|
|
|
static func refreshTokenIfDoesntExist(completionHandler: @escaping () -> Void) {
|
... | ... | @@ -459,8 +458,7 @@ class BearerTokenHandler { |
|
|
|
|
|
completionHandler()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
</details>
|
|
|
|
|
|
Then you assign the `BearerRequestBuilderFactory` to the property requestBuilderFactory in the APIs.swift file.
|
... | ... | |