protobuf-net / protobuf-net

Protocol Buffers library for idiomatic .NET
Other
4.69k stars 1.06k forks source link

Generating a proto file based on a class library or public inteface files #732

Open ebonat opened 3 years ago

ebonat commented 3 years ago

Hi All,

A simple C# class library will have many public methods to be consume by any client. I would like to design and build a gRPC service for it. I don't want to write and maintain the proto file for it at all. Is there any way to generate the proto file automatically based on the class library implementation or defined public interface using protobuf-net?

Thank you for your help,

-Ernest

jstafford5380 commented 3 years ago

Seems pretty relevant to me. I was expecting this to be a base function of the library. We'd want to have that proto file generated much how an OpenAPI (swagger) spec would generated by swashbuckle at build or runtime, so it can be pushed to a registry (or api management service) for other components to import.

mgravell commented 3 years ago

A version of this code does exist, in protobuf-net.Grpc.Reflection ; I haven't had time to put samples together yet.

On Fri, 15 Jan 2021, 20:52 jstafford5380, notifications@github.com wrote:

Seems pretty relevant to me. I was expecting this to be a base function of the library. We'd want to have that proto file generated much how an OpenAPI (swagger) spec would generated by swashbuckle at build or runtime, so it can be pushed to a registry (or api management service) for other components to import.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/protobuf-net/protobuf-net/issues/732#issuecomment-761191507, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMAAXTECSOZOGDY6DS3S2CTIXANCNFSM4UJJ22YA .

ebonat commented 3 years ago

hi marc,

thank you for your post. please if you can post some examples that be very appreciated. i can't spend weeks writing the proto files for many c# legacy libraries we have in my company. is there any links available to start reading or coding about it?

mgravell commented 3 years ago

Shirt version: GetSchema, here: https://github.com/protobuf-net/protobuf-net.Grpc/blob/main/src/protobuf-net.Grpc.Reflection/SchemaGenerator.cs

Longer version : needs me to have some spare time

On Sat, 16 Jan 2021, 15:08 Ernest Bonat, Ph.D., notifications@github.com wrote:

hi marc,

thank you for your post. please if you can post some examples that be very appreciated. i can't spend weeks writing the proto files for many c# legacy libraries we have in my company. is there any links available to start reading about or coding about it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/protobuf-net/protobuf-net/issues/732#issuecomment-761578811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMBWYUPMRFTL43TLWN3S2GTX5ANCNFSM4UJJ22YA .

ebonat commented 3 years ago

thanks marc,

good point to start to. at least 1 or 2 examples in the long version will be the best! thanks again.

jstafford5380 commented 3 years ago

How would I use this practically though? So I can output it at runtime which is something, but how do I get that into a catalog? Is the thought that I would have to configure a "docs" build to start it up, call an endpoint, dump the content to a file and push it to the catalog? Or am I missing something?

Would it be better to have this library output to a local file on local build? In other words, the reverse of what Grpc.Tools does (outputs .cs files in the background)