fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.35k stars 497 forks source link

Cannot list methods of a service and make requests #451

Closed ttc0419 closed 2 months ago

ttc0419 commented 2 months ago

When I list services, it works as intended:

[u]% grpcurl -plaintext 127.0.0.1:5443 list
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
xxx.yyy

But when I was trying to list the methods:

[u]% grpcurl -plaintext 127.0.0.1:5443 list 'xxx.yyy'
Failed to list methods for service "xxx.yyy": Symbol not found: xxx.yyy
caused by: File not found: openapi/v3/annotations.proto

And it cannot invoke GRPCs as well:

[u]% grpcurl -d 'some json data' -plaintext 127.0.0.1:5443 '/xxx.yyy/Get'
Error invoking method "/xxx.yyy/Get": target server does not expose service "/xxx.yyy"
jhump commented 2 months ago

You can provide the schema yourself by providing proto source files are a compiled file descriptor set (using the -o argument of protoc or using buf build). But the issue here is that the reflection endpoint in the server is unable to provide the entire schema. As it states, it cannot provide a file descriptor for the import openapi/v3/annotations.proto.

This is an issue with how the Gnostic stuff is being used. For reflection to correctly work, the path you use in an import statement must match the path used when that file was compiled to generated Go code. This comment suggests you should be arranging your file system structure to so that the import statement is "openapiv3/annotations.proto" (no slash between "openapi" and "v3").

I can also look at updating my grpcreflect package to try to be lenient about this sort of thing. Generally, all of a file's imports must be present in order to properly construct a schema model for elements in that file. However, imports that only supply custom options could actually be omitted and the schema could still be constructed. The result is that any custom options would be uninterpreted, which would work for grpcurl and grpcui since they don't care about custom options (though it does mean that custom options would be absent when you try to describe an element with grpcurl).