connectrpc/connect-swift

Generated Mocks don't include import to connect interface definition

ivanvanderbyl opened this issue · 4 comments

The generated mocks don't import the actual protocol they are implementing, making this unusable at compile time.

Taking the example from the docs:

import Combine
import Connect
import ConnectMocks
import Foundation
import SwiftProtobuf

/// Mock implementation of `Connectrpc_Eliza_V1_ElizaServiceClientInterface`.
open class Connectrpc_Eliza_V1_ElizaServiceClientMock: Connectrpc_Eliza_V1_ElizaServiceClientInterface, @unchecked Sendable {
   ...  
}

There should be an import for something that provides Connectrpc_Eliza_V1_ElizaServiceClientInterface

👋🏽 @ivanvanderbyl, thanks for filing this issue. The example from the docs doesn't make any assumptions about how consumers modularize generated sources since that decision typically varies by project. Instead, it assumes all generated sources live in the same module. It sounds like you are trying to place mocks in a separate module from the production sources - can you share your module structure?

Also, Buf's Generated SDKs solve this problem automatically through Swift Package Manager if you're interested in checking that out: https://buf.build/solutions/generate-sdks

@rebello95 thanks for the quick reply. I am using Buf's generated SDKs, so they are naturally in a separate module. Here's the output of my generated code from BSR:

import Connect
import ConnectMocks
import Foundation
import Ivandev_ObservablePipeline_Apple_Swift
import SwiftProtobuf

    /// Mock implementation of `Scanner_V1alpha1_ScannerServiceClientInterface`.
@available(iOS 13, *)
open class ScannerServiceClientMock: Scanner_V1alpha1_ScannerServiceClientInterface, @unchecked Sendable {

It should be importing Ivandev_ObservablePipeline_Connectrpc_Swift as well as the Apple Swift mocks.

Thanks for the info. That should work, so I'm wondering if there was a regression on the Buf side. Can you please ask this question in the Buf Slack? Someone should be able to help debug more there: https://buf.build/links/slack

Looks like this is resolved by bufbuild/plugins#1140