Skip to content

Commit 49b30b8

Browse files
authored
Fix package namespace ref (#102)
* Fix namespace reference issue * Add tests for namespace handling in code generation Co-authored-by: jaakkor2
1 parent 7cfad6b commit 49b30b8

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/ProtoBuf.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ function service_cb(io, t::CodeGenerators.ServiceType, ctx::CodeGenerators.Conte
99
response_type = rpc.response_type.name
1010

1111
if rpc.request_type.package_namespace !== nothing
12-
request_type = join([rpc.package_namespace, request_type], ".")
12+
request_type = join([rpc.request_type.package_namespace, request_type], ".")
1313
end
1414
if rpc.response_type.package_namespace !== nothing
15-
response_type = join([rpc.package_namespace, response_type], ".")
15+
response_type = join([rpc.response_type.package_namespace, response_type], ".")
1616
end
1717

1818
export_name = "$(service_name)_$(rpc.name)_Client"

test/proto/ext_service.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
syntax = "proto3";
2+
package ext_service;
3+
4+
import "ext_types.proto";
5+
6+
service ExtService {
7+
rpc ExtRPC(ext_types.ExtRequest) returns (ext_types.ExtResponse) {}
8+
rpc ExtStreamRPC(ext_types.ExtRequest) returns (stream ext_types.ExtResponse) {}
9+
}

test/proto/ext_types.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
syntax = "proto3";
2+
package ext_types;
3+
4+
message ExtRequest {
5+
uint64 id = 1;
6+
}
7+
8+
message ExtResponse {
9+
uint64 result = 1;
10+
}

test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ include("gen/test/test_pb.jl")
9292
@test contains(generated, "export TestService_TestClientStreamRPC_Client")
9393
@test contains(generated, "export TestService_TestBidirectionalStreamRPC_Client")
9494
end
95+
96+
# Test that request/response type package_namespace is correctly applied when types
97+
# come from a different proto package. Previously this was broken because the code
98+
# checked rpc.package_namespace instead of rpc.request_type.package_namespace and
99+
# rpc.response_type.package_namespace.
100+
mktempdir() do tmpdir
101+
@test isnothing(protojl("ext_service.proto", joinpath(@__DIR__, "proto"), tmpdir))
102+
generated = read(joinpath(tmpdir, "ext_service", "ext_service_pb.jl"), String)
103+
# Request type from ext_types package must be prefixed with package namespace
104+
@test contains(generated, "ext_types.ExtRequest")
105+
# Response type from ext_types package must be prefixed with package namespace
106+
@test contains(generated, "ext_types.ExtResponse")
107+
# Full type parameter string with both namespaced types
108+
@test contains(generated, "gRPCClient.gRPCServiceClient{ext_types.ExtRequest, false, ext_types.ExtResponse, false}")
109+
@test contains(generated, "gRPCClient.gRPCServiceClient{ext_types.ExtRequest, false, ext_types.ExtResponse, true}")
110+
# Service client constructors are present
111+
@test contains(generated, "ExtService_ExtRPC_Client(")
112+
@test contains(generated, "ExtService_ExtStreamRPC_Client(")
113+
end
95114
end
96115

97116
@testset "@async varying request/response" begin

0 commit comments

Comments
 (0)