2

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

4
  • 1
    Maybe the signature of func intercept(...) has changed in the OpenAPI version you are using compared to the docs example. Commented Oct 14 at 13:13
  • I considered that, so I pulled the declaration directly from the framework source code to ensure that it was up to date. Commented Oct 14 at 13:18
  • @workingdogsupportUkraine is right. I faced the same issue, was able to build without any change apart from downgrading the (dependency) package version Commented Oct 20 at 19:37
  • Bro have you found something for this? I have been running around in circles for a week now! Commented Nov 9 at 10:40

2 Answers 2

2

I have finally found the answer, after 5 days of going through everything.

The solution is to change one "Build Settings" setting named "Approachable Concurrency" from Yes to No (refer to the screenshot)

enter image description here

Or if you have VScode, open your project "project.pbxproj" file and change this here

enter image description here

If you have any questions or further additions please ask away.

Sign up to request clarification or add additional context in comments.

Comments

0

After some fiddling I figured out that if I abstracted the middlewear code into it's own swift package library I could get it to compile outside Xcode and them import the library into Xcode. It's possible there was some sort of namespace collision, but even explicitly specifying the module for each type didn't solve it so I'm still not sure what was going on. Any insights would be appreciated for future learning.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.