Reputation: 7219
Following the docs on how to set up a gRPC gateway, I find myself stuck at step four of generating the grpc gateway.
Namely, things fall apart when the following line is added:
import "google/api/annotations.proto";
The documentation says You will need to provide the required third party protobuf files to the protoc compiler
- but not actually how do do so.
How do I add google/api/annotations.proto
as a dependency?
Upvotes: 22
Views: 73184
Reputation: 71
For C# and Visual Studio this is a working method:
<PropertyGroup>
...
<IncludeHttpRuleProtos>true</IncludeHttpRuleProtos>
</PropertyGroup>
Upvotes: 1
Reputation: 199
You can manage your dependencies using buf. See the following snippet of their documentation:
You will need to provide the required third party protobuf files to the protobuf compiler. If you are using buf, this dependency can be added to the deps array in your buf.yaml under the name buf.build/googleapis/googleapis:
version: v1 name: buf.build/yourorg/myprotos deps: - buf.build/googleapis/googleapis
Always run buf mod update after adding a dependency to your buf.yaml.
Upvotes: 0
Reputation: 2881
What worked for me was:
import "google/api/annotations.proto";
import "google/api/http.proto";
with the same structure as explained here: https://grpc-ecosystem.github.io/grpc-gateway/docs/tutorials/adding_annotations/#using-protoc
Upvotes: 0
Reputation: 987
I am using Visual Studio. My proto file hierarchy looks like this:
I had to adjust the ProtoRoot
property of the items in the csproj file like this:
<ItemGroup>
<Protobuf Include="Protos\authzed\api\v1\experimental_service.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\google\api\annotations.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\google\api\http.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\google\rpc\status.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\protoc-gen-openapiv2\options\annotations.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\protoc-gen-openapiv2\options\openapiv2.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\validate\validate.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\core.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\debug.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\error_reason.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\openapi.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\permission_service.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\schema_service.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
<Protobuf Include="Protos\authzed\api\v1\watch_service.proto" GrpcServices="Client" ProtoRoot="Protos\" Access="Internal" />
</ItemGroup>
Upvotes: 2
Reputation: 445
Sometimes this error occurs when we run protoc . try to import the dependency when running the protoc command.
for this type of structure use
>protoc -I . -I pb/google/api --go_out . --go_opt paths=source_relative --go-grpc_out . --go-grpc_opt paths=source_relative --grpc-gateway_out . --grpc-gateway_opt paths=source_relative ./pb/*.proto
Upvotes: 0
Reputation: 2399
If you are using protoc to generate stubs, you need to ensure the required dependencies are available to the compiler at compile time. These can be found by manually cloning and copying the relevant files from the googleapis repository, and providing them to protoc when running. The files you will need are:
google/api/annotations.proto
google/api/field_behaviour.proto
google/api/http.proto
google/api/httpbody.proto
from grpc-gateway
for example run in project root
git submodule add https://github.com/googleapis/googleapis
to get actual version
Upvotes: 2
Reputation: 1044
I had the same issue and i resolved it following this structure :
proto
├── google
│ └── api
│ ├── annotations.proto
│ └── http.proto
└── helloworld
└── hello_world.proto
and run the command :
protoc -I ./proto \
--go_out ./proto --go_opt paths=source_relative \
--go-grpc_out ./proto --go-grpc_opt paths=source_relative \
--grpc-gateway_out ./proto --grpc-gateway_opt paths=source_relative \
./proto/helloworld/hello_world.proto
Upvotes: 13
Reputation: 7219
I solved it one way by adding third party google apis and its content to the root of my project.
Feels wrong, but apparently this is encouraged
Upvotes: 19
Reputation: 325
I solved it with only copying annotations.proto and http.proto in the main proto:
import "Proto/google/api/annotations.proto";
and inside annotations.proto
import "Proto/google/api/http.proto";
and my folders look like this:
Upvotes: 3