When creating a new Authentication Middleware class that conforms to the ClientMiddleware protocol defined in the swift-openapi-runtime library, Xcode reports that the class does not conform to the protocol, even though the class implements the required function defined in the protocol.
I have tried using Xcodes generated protocol stubs, I have tried copying and pasting the function declaration from the protocol definition. Neither approache have resolved the error. The implemented codes is shown below:
import Foundation
import OpenAPIURLSession
import OpenAPIRuntime
import HTTPTypes
/// Injects an authorization header to every request.
struct AuthenticationMiddleware {
/// The token value.
var bearerToken: String
}
extension AuthenticationMiddleware: ClientMiddleware {
func intercept(
_ request: HTTPRequest,
body: HTTPBody?,
baseURL: URL,
operationID: String,
next: @Sendable (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)
) async throws -> (HTTPResponse, HTTPBody?) {
var request = request
request.headerFields[.authorization] = "Bearer \(bearerToken)"
return try await next(request, body, baseURL)
}
}
An image of the error within Xcode is shown below:
XCode error thrown for protocol noncomplience


func intercept(...)has changed in the OpenAPI version you are using compared to the docs example.