Browse Source

Always include the 'SwiftProtobuf' import in generated code (#16)

Motivation:

The 'SwiftProtobuf' import was missing from generated code.

Modifications:

- Always generate an import for 'SwiftProtobuf'

Result:

Import are more correct
George Barnett 1 year ago
parent
commit
4587c27d7c

+ 2 - 1
Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift

@@ -96,7 +96,8 @@ extension ProtobufCodeGenParser {
     file: FileDescriptor
   ) -> [Dependency] {
     var codeDependencies: [Dependency] = [
-      .init(module: "GRPCProtobuf", accessLevel: .internal)
+      Dependency(module: "GRPCProtobuf", accessLevel: .internal),
+      Dependency(module: "SwiftProtobuf", accessLevel: self.accessLevel),
     ]
     // Adding as dependencies the modules containing generated code or types for
     // '.proto' files imported in the '.proto' file we are parsing.

+ 4 - 2
Tests/GRPCProtobufCodeGenTests/ProtobufCodeGenParserTests.swift

@@ -61,7 +61,8 @@ struct ProtobufCodeGenParserTests {
     @Test("Dependencies")
     func dependencies() {
       let expected: [GRPCCodeGen.Dependency] = [
-        .init(module: "GRPCProtobuf", accessLevel: .internal)  // Always an internal import
+        .init(module: "GRPCProtobuf", accessLevel: .internal),  // Always an internal import
+        .init(module: "SwiftProtobuf", accessLevel: .internal),
       ]
       #expect(self.codeGen.dependencies == expected)
     }
@@ -173,7 +174,8 @@ struct ProtobufCodeGenParserTests {
     @Test("Dependencies")
     func dependencies() {
       let expected: [GRPCCodeGen.Dependency] = [
-        .init(module: "GRPCProtobuf", accessLevel: .internal)  // Always an internal import
+        .init(module: "GRPCProtobuf", accessLevel: .internal),  // Always an internal import
+        .init(module: "SwiftProtobuf", accessLevel: .internal),
       ]
       #expect(self.codeGen.dependencies == expected)
     }

+ 1 - 0
Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift

@@ -67,6 +67,7 @@ struct ProtobufCodeGeneratorTests: UsesDescriptorSet {
 
       import GRPCCore
       import GRPCProtobuf
+      import SwiftProtobuf
 
       // MARK: - test.TestService