diff --git a/src/ProtoBuf.jl b/src/ProtoBuf.jl index 9a1f935..b193709 100644 --- a/src/ProtoBuf.jl +++ b/src/ProtoBuf.jl @@ -9,10 +9,10 @@ function service_cb(io, t::CodeGenerators.ServiceType, ctx::CodeGenerators.Conte response_type = rpc.response_type.name if rpc.request_type.package_namespace !== nothing - request_type = join([rpc.package_namespace, request_type], ".") + request_type = join([rpc.request_type.package_namespace, request_type], ".") end if rpc.response_type.package_namespace !== nothing - response_type = join([rpc.package_namespace, response_type], ".") + response_type = join([rpc.response_type.package_namespace, response_type], ".") end export_name = "$(service_name)_$(rpc.name)_Client" diff --git a/test/proto/ext_service.proto b/test/proto/ext_service.proto new file mode 100644 index 0000000..cb7b7fc --- /dev/null +++ b/test/proto/ext_service.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package ext_service; + +import "ext_types.proto"; + +service ExtService { + rpc ExtRPC(ext_types.ExtRequest) returns (ext_types.ExtResponse) {} + rpc ExtStreamRPC(ext_types.ExtRequest) returns (stream ext_types.ExtResponse) {} +} diff --git a/test/proto/ext_types.proto b/test/proto/ext_types.proto new file mode 100644 index 0000000..91c4bce --- /dev/null +++ b/test/proto/ext_types.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package ext_types; + +message ExtRequest { + uint64 id = 1; +} + +message ExtResponse { + uint64 result = 1; +} diff --git a/test/runtests.jl b/test/runtests.jl index 49784eb..29e4a93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -96,6 +96,25 @@ include("gen/test/test_pb.jl") @test contains(generated, "export TestService_TestClientStreamRPC_Client") @test contains(generated, "export TestService_TestBidirectionalStreamRPC_Client") end + + # Test that request/response type package_namespace is correctly applied when types + # come from a different proto package. Previously this was broken because the code + # checked rpc.package_namespace instead of rpc.request_type.package_namespace and + # rpc.response_type.package_namespace. + mktempdir() do tmpdir + @test isnothing(protojl("ext_service.proto", joinpath(@__DIR__, "proto"), tmpdir)) + generated = read(joinpath(tmpdir, "ext_service", "ext_service_pb.jl"), String) + # Request type from ext_types package must be prefixed with package namespace + @test contains(generated, "ext_types.ExtRequest") + # Response type from ext_types package must be prefixed with package namespace + @test contains(generated, "ext_types.ExtResponse") + # Full type parameter string with both namespaced types + @test contains(generated, "gRPCClient.gRPCServiceClient{ext_types.ExtRequest, false, ext_types.ExtResponse, false}") + @test contains(generated, "gRPCClient.gRPCServiceClient{ext_types.ExtRequest, false, ext_types.ExtResponse, true}") + # Service client constructors are present + @test contains(generated, "ExtService_ExtRPC_Client(") + @test contains(generated, "ExtService_ExtStreamRPC_Client(") + end end @testset "@async varying request/response" begin