Skip to content

Error when implementing a middleware with SWIFT_APPROACHABLE_CONCURRENCY #804

Closed as not planned

Description

@joaocolaco

Question

Since Xcode 26 beta 5 i cannot comply with the ClientMiddleware protocol of swift-openapi-runtime. The error that I got is Candidate has non-matching type '(HTTPRequest, HTTPBody?, URL, String, nonisolated(nonsending) @Sendable (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)) async throws -> (HTTPResponse, HTTPBody?)' for a structure that seems (and was) to be well "made":

public struct ApiKeyMiddleware: ClientMiddleware {

   //The API key to login
    private let apiKey: String
    
    
    public init(apiKey: String) { self.apiKey = apiKey }

    public func intercept(
        _ request: HTTPRequest,
        body: HTTPBody?,
        baseURL: URL,
        operationID: String,
        next:  @Sendable (HTTPRequest, HTTPBody?, URL) async throws -> (
            HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?
        )
    ) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?) {
        var request = request
        request.headerFields[.init("x-goog-api-key")!] = self.apiKey
        return try await next(request, body, baseURL)
    }
}

Is this an Xcode/Swift bug or is there something that I'm missing?

Thanks

Activity

  1. added
    status/triageCollecting information required to triage the issue.
    kind/supportAdopter support requests.
    on Aug 7, 2025
  2. BrentMifsud commented on Aug 7, 2025

    @BrentMifsud

    running into the exact same problem. There doesn't seem to be a way to prevent Xcode from automatically adding nonisolated(nonsending) to the implementation as far as I can tell.

  3. czechboy0 commented on Aug 8, 2025

    @czechboy0
    Contributor

    Ok, seems to be happening only with the SWIFT_APPROACHABLE_CONCURRENCY=YES build setting. While we investigate this, one workaround is to create a dedicated target for your middleware/generated code, and ensure the build setting is turned off in that target only.

    Edit: An easier workaround is to add @concurrent to the next parameter, before @Sendable, making it:

    next: @concurrent @Sendable (HTTPRequest, HTTPBody?, URL) ...
  4. changed the title [-]`ClientMiddleware` compliant structure not compliant since Xcode 26 beta 5[/-] [+]Error when implementing a middleware with SWIFT_APPROACHABLE_CONCURRENCY[/+] on Aug 8, 2025
  5. pinned this issue on Oct 29, 2025
  6. unpinned this issue on Aug 6, 2026
  7. pinned this issue on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/supportAdopter support requests.status/triageCollecting information required to triage the issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions