alfianlosari / aitext2imageapp

AI Text2Image iOS App with OpenAPI <> OpenAI Swift Client Generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update to ClientMiddleware

kyleroche opened this issue · comments

I had to update the ClientMIddleware to the following to get this example to run.

struct AuthMiddleware: ClientMiddleware {
    let apiKey: String
    
    func intercept(_ request: HTTPRequest, body: HTTPBody?, baseURL: URL, operationID: String, next: (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)) async throws -> (HTTPResponse, HTTPBody?) {
        var request = request
        request.headerFields.append(
            .init(name: HTTPField.Name.authorization, value: "Bearer \(apiKey)")
        )
        return try await next(request, body, baseURL)
    }
}

also had to import HTTPTypes