arthurnn / twirp-ruby

Twirp services in Ruby
Apache License 2.0
155 stars 60 forks source link

Missing module name in _twirp generated code #48

Open Ziaw opened 4 years ago

Ziaw commented 4 years ago

When I generate code from two proto files

// data.proto
syntax = "proto3";
import "ok.proto";

service Data {
    rpc create(SetDataRequest) returns (ok.Response);
}

message SetDataRequest {
    string uuid = 1;
}
// ok.proto
syntax = "proto3";
package ok;

message Response { }

With one protoc execute

protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --plugin=/Users/a.zimin/go/bin/protoc-gen-twirp_ruby data.proto ok.proto

I have a code with a missing module name of Response class

# data_twirp.rb
# Code generated by protoc-gen-twirp_ruby 1.4.1, DO NOT EDIT.
# ...SKIP...
  rpc :create, SetDataRequest, Response, :ruby_method => :create
# ...SKIP...
module Ok
  Response = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("ok.Response").msgclass
end

With two protoc calls

protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --plugin=/Users/a.zimin/go/bin/protoc-gen-twirp_ruby data.proto
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --plugin=/Users/a.zimin/go/bin/protoc-gen-twirp_ruby ok.proto

Generated code is correct

# data_twirp.rb
# ...SKIP...
  rpc :create, SetDataRequest, Ok::Response, :ruby_method => :create
# ...SKIP...
arthurnn commented 1 year ago

Is this still a problem on latest version? would you mind double checking? 🙏

angristan commented 1 month ago

👋 Encountered the same issue. The proposed solution (running protoc for each file instead of running once for all files) works.