grpcurl icon indicating copy to clipboard operation
grpcurl copied to clipboard

Proto generation

Open wahmedswl opened this issue 4 years ago • 5 comments

Hi, can we export proto from grpc server reflection?

Thanks

wahmedswl avatar Jan 27 '21 21:01 wahmedswl

@wahmedswl, yes. Run grpcurl -h and then take a look at the -protoset-out. Note, however, that this exports a FileDescriptorSet that is written in the binary protobuf format. It does not produce proto sources.

Though you could use the packages in https://github.com/jhump/protoreflect to translate them into source files. You'd have to write some Go code to make that happen.

jhump avatar Jan 27 '21 21:01 jhump

Nice, can this be integrated within grpcurl? This is something useful.

Thanks

wahmedswl avatar Jan 27 '21 21:01 wahmedswl

Alternatively, grpcurl could follow up on #57 and add a -recursive option to describe, so that the whole accessible "tree" of services and types would be described in a protobuf format (bonus points if we could filter out grpc.reflection.* and exclude the "x.Y is a service" comments :wink: ). This would probably miss a lot of corner-cases, but might be useful enough regardless? Would an PR in this direction be considered? Or am I missing some obvious deal-breaker?

costela avatar May 11 '21 15:05 costela

@costela, I'm not sure that would really work. The resulting source would not be compile-able unless it emitted, at a minimum, one file per referenced package. IMO, it would ideally be one file per actual input source file that defined the schema, which is how -protoset-out works.

So it needs to be special-cased to support multi-file export; it's not sufficient to just print the transitive closure of all elements independently as if in one file. I'm thinking that it would instead be a -proto-out option, where the resulting output will be a ZIP file, with possibly multiple proto source files inside.

jhump avatar May 11 '21 16:05 jhump

@jhump ah yes, that makes sense. I'm coming from the "easy" case of single package proto definitions, so it would be enough for us, but not for a lot of other people.

Just out of curiosity, why do you suggest zipping the output (as opposed to, e.g. --proto-out-dir)?

costela avatar May 25 '21 13:05 costela