-
Notifications
You must be signed in to change notification settings - Fork 158
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
Absolute imports for proto files in the same directory not working #116
Comments
when you're not using gripmock, how you pass the argument into protoc? |
I have similar issue. Service references shared models (shared between multiple services) and I add them as to imports.
With
And if I try to add common proto to list of protos explicitly (i.e. '/common/XXX/api/rpc/empty_response.proto' '/proto/AccountService.proto'), it fails like in author's case that type is already defined:
To generate real service code we use dotnet Grpc.Tools, which also uses protoc under the hood, and from logs I see it simly uses multiple --proto_path directives w/o any issue, so it seems like some Go specific issue, but I'm not sure how to diagnose :) |
Here is simplified example of the issue (see code attached test.zip)
If using some imports from external folder, getting error:
And to reproduce author's behavior, add dependency to compile explicitly and it fails with duplicated definitions:
|
+1 , we also have same issue. |
I solved the issue by specifying all imported files explicitly along the main proto file. It would be helpful if gripmock could accept path pattern (glob) and expand it automatically like:
https://stackoverflow.com/questions/26809484/how-to-use-double-star-glob-in-go |
Absolute imports for
proto
files in the same directory not workingIn case two or more proto files are in the same package and there is a dependency between them, the go code generation will not work correctly in case the import statement is provided in absolute path. It works correctly if the import statement is relative.
Example:
In a project with the following directory structure:
❯ tree . ├── proto │ └── account │ ├── models.proto │ └── services.proto └── readme.md
where the files have the following content:
models.proto
services.proto
In this example we have a
services.proto
which defines the grpc services and amodels.proto
which defines the models for the service.services.proto
importsmodels.proto
and both are in the same package and define same go_package. Notice how the--imports
flag allowsgripmock
to find themodels.proto
but it seems like it is found twice and therefore issues an error. The command below is issued from the project root:Interestingly enough, changing the import statement in
services.proto
fromimport "account/models.proto";
toimport "models.proto";
works.Attached you can find a zip file containing the project to reproduce the issue.
absolute-import-path-bug.zip
The text was updated successfully, but these errors were encountered: