Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of import public "file.proto" #139

Closed
fiorix opened this issue Apr 23, 2016 · 6 comments
Closed

Handling of import public "file.proto" #139

fiorix opened this issue Apr 23, 2016 · 6 comments

Comments

@fiorix
Copy link

fiorix commented Apr 23, 2016

When I use import public "file.proto" the generated .pb.go file contains my API + the public import ones. However, the pb.gw.go file does not.

Is that expected, am I missing something?

@yugui
Copy link
Member

yugui commented Apr 25, 2016

It might be a bug because I didn't consider import public when I implemented the code generator.
But I am not sure if I understand the problem you saw for the same reason.

Could you give me a more concrete example, what you expected and what you got?

@fiorix
Copy link
Author

fiorix commented Apr 25, 2016

I had like 3 proto files used for specific things. Then elsewhere in another proto file I would import public all of them, and generate the proxy for the entire API. The .pb.go comes out right, but the .gw.go one does not include anything from the imported files.

@yugui
Copy link
Member

yugui commented Apr 25, 2016

I guess a scenario something like the followings.

  • You had a.proto, b.proto and c.proto in a package. a.proto contained something like
    protobuf message A{ }
  • You also had another file x.proto in another package, which contained
    protobuf import public "path/to/a.proto";
  • You expected that you get a gateway imports imports the package of message A because protoc-gen-go does so. But actually the gateway generator didn't.

But as far as I understand, import public does not transitively forward services unlike messages.
So I don't think it caused compilation error or something even if the generated .gw.go lacks a reference to the other package. What exactly problem did you have?

@fiorix
Copy link
Author

fiorix commented Apr 25, 2016

a.proto:

syntax = "proto3";

package a;

service Echo {
    rpc Echo(EchoRequest) returns (EchoResponse) {}
}

message EchoRequest {
    string Text = 1;
}

message EchoResponse {
    string Text = 1;
}

b.proto:

syntax = "proto3";

package b;

service Ping {
    rpc Ping(PingRequest) returns (PingResponse) {}
}

message PingRequest {
    string Text = 1;
}

message PingResponse {
    string Text = 1;
}

root.proto:

syntax = "proto3";

package root;

import public "a.proto";
import public "b.proto";

When I generate the root.pb.go I get all types from a and b. The gateway and swagger ones are empty.

@yugui
Copy link
Member

yugui commented Apr 25, 2016

You won't see message definition unless it is actually used in services.
You never see message definition at all in .gw.go because it is intended to be compiled together with .pb.go.

@fiorix
Copy link
Author

fiorix commented Apr 25, 2016

Sure, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants