diff --git a/docs/faq-generators.md b/docs/faq-generators.md index 7023e595a3c..8dc026da772 100644 --- a/docs/faq-generators.md +++ b/docs/faq-generators.md @@ -100,9 +100,9 @@ There is a new `swift6` generator, that is currently in beta, try it and give us ### How do I implement bearer token authentication with URLSession on the Swift 5 API client? -
- First you subclass RequestBuilderFactory +First you subclass RequestBuilderFactory +``` class BearerRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { BearerRequestBuilder.self @@ -112,11 +112,10 @@ There is a new `swift6` generator, that is currently in beta, try it and give us BearerDecodableRequestBuilder.self } } -
- -
- Then you subclass URLSessionRequestBuilder and URLSessionDecodableRequestBuilder +``` +Then you subclass URLSessionRequestBuilder and URLSessionDecodableRequestBuilder +``` class BearerRequestBuilder: URLSessionRequestBuilder { @discardableResult override func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (Result, ErrorResponse>) -> Void) -> RequestTask { @@ -245,8 +244,7 @@ There is a new `swift6` generator, that is currently in beta, try it and give us completionHandler() } } - -
+``` Then you assign the `BearerRequestBuilderFactory` to the property `requestBuilderFactory`. @@ -260,9 +258,9 @@ Here is a working sample that put's together all of this. ### How do I implement bearer token authentication with Alamofire on the Swift 5 API client? -
- First you subclass RequestBuilderFactory +First you subclass RequestBuilderFactory +``` class BearerRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { BearerRequestBuilder.self @@ -272,11 +270,10 @@ Here is a working sample that put's together all of this. BearerDecodableRequestBuilder.self } } -
- -
- Then you subclass AlamofireRequestBuilder and AlamofireDecodableRequestBuilder +``` +Then you subclass AlamofireRequestBuilder and AlamofireDecodableRequestBuilder +``` class BearerRequestBuilder: AlamofireRequestBuilder { override func createSessionManager() -> SessionManager { let sessionManager = super.createSessionManager() @@ -334,7 +331,7 @@ Here is a working sample that put's together all of this. completionHandler(true) } } -
+``` Then you assign the `BearerRequestBuilderFactory` to the property `requestBuilderFactory`. @@ -348,8 +345,8 @@ Here is a working sample that put's together all of this. ### How do I implement bearer token authentication with URLSession on the Swift 6 API client? -
- First you implement the `OpenAPIInterceptor` protocol. +First you implement the `OpenAPIInterceptor` protocol. +``` public class BearerOpenAPIInterceptor: OpenAPIInterceptor { public init() {} @@ -419,7 +416,7 @@ public class BearerOpenAPIInterceptor: OpenAPIInterceptor { completionHandler(dummyBearerToken) } } -
+``` Then you assign the `BearerOpenAPIInterceptor` to the property `OpenAPIClient.shared.interceptor`. @@ -431,8 +428,8 @@ Here is a working sample that put's together all of this. ### How do I implement bearer token authentication with Alamofire on the Swift 6 API client? -
- First implement the `Alamofire` `RequestInterceptor` protocol. +First implement the `Alamofire` `RequestInterceptor` protocol. +``` class BearerTokenHandler: RequestInterceptor, @unchecked Sendable { private var bearerToken: String? = nil @@ -468,7 +465,7 @@ class BearerTokenHandler: RequestInterceptor, @unchecked Sendable { completionHandler(true) } } -
+``` Then you assign the `BearerTokenHandler` to the property `OpenAPIClient.shared.interceptor`.