Skip to content

Commit

Permalink
Always include the 'SwiftProtobuf' import in generated code (#16)
Browse files Browse the repository at this point in the history
Motivation:

The 'SwiftProtobuf' import was missing from generated code.

Modifications:

- Always generate an import for 'SwiftProtobuf'

Result:

Import are more correct
  • Loading branch information
glbrntt authored Dec 3, 2024
1 parent 66dd0ce commit 4587c27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct ProtobufCodeGeneratorTests: UsesDescriptorSet {
import GRPCCore
import GRPCProtobuf
import SwiftProtobuf
// MARK: - test.TestService
Expand Down

0 comments on commit 4587c27

Please sign in to comment.