diff --git a/src/compiler/ruby_generator_string-inl.h b/src/compiler/ruby_generator_string-inl.h index b3e19386c80..968f795cbb5 100644 --- a/src/compiler/ruby_generator_string-inl.h +++ b/src/compiler/ruby_generator_string-inl.h @@ -124,7 +124,7 @@ inline std::string RubyTypeOf(const grpc::protobuf::Descriptor* descriptor) { ReplacePrefix(&proto_type, ".", ""); // remove the leading . (no package) proto_type = RubyPackage(descriptor->file()) + "." + proto_type; } - std::string res(proto_type); + std::string res("." + proto_type); if (res.find('.') == std::string::npos) { return res; } else { diff --git a/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto b/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto new file mode 100644 index 00000000000..15dd8f0aec9 --- /dev/null +++ b/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto @@ -0,0 +1,27 @@ +// Copyright 2020 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package same_name; + +service SameName { + rpc Health(Request) returns (Status); +} + +message Status { + string msg = 1; +} + +message Request {} diff --git a/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto b/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto new file mode 100644 index 00000000000..9ce631ca5b6 --- /dev/null +++ b/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto @@ -0,0 +1,29 @@ +// Copyright 2020 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package other_name; + +option ruby_package = "SameName2"; + +service SameName2 { + rpc Health(Request) returns (Status); +} + +message Status { + string msg = 1; +} + +message Request {} diff --git a/src/ruby/spec/pb/codegen/package_option_spec.rb b/src/ruby/spec/pb/codegen/package_option_spec.rb index a4668ace520..f64b4f6aa62 100644 --- a/src/ruby/spec/pb/codegen/package_option_spec.rb +++ b/src/ruby/spec/pb/codegen/package_option_spec.rb @@ -48,6 +48,26 @@ describe 'Code Generation Options' do expect(services[:NestedMessageTest].output).to eq(RPC::Test::New::Package::Options::Bar::Baz) end end + + it 'should generate when package and service has same name' do + with_protos(['grpc/testing/same_package_service_name.proto']) do + expect { SameName::SameName::Service }.to raise_error(NameError) + expect(require('grpc/testing/same_package_service_name_services_pb')).to be_truthy + expect { SameName::SameName::Service }.to_not raise_error + expect { SameName::Request }.to_not raise_error + expect { SameName::Status }.to_not raise_error + end + end + + it 'should generate when ruby_package and service has same name' do + with_protos(['grpc/testing/same_ruby_package_service_name.proto']) do + expect { SameName2::SameName2::Service }.to raise_error(NameError) + expect(require('grpc/testing/same_ruby_package_service_name_services_pb')).to be_truthy + expect { SameName2::SameName2::Service }.to_not raise_error + expect { SameName2::Request }.to_not raise_error + expect { SameName2::Status }.to_not raise_error + end + end end def with_protos(file_paths)