chrusty / protoc-gen-jsonschema

Protobuf to JSON-Schema compiler
Apache License 2.0
496 stars 101 forks source link

Possible to allow internal/converter to be imported by other packages? #142

Closed k-jay-c closed 1 year ago

k-jay-c commented 1 year ago

Hi,

I was looking for a package that converts protobuf to JSONSchema and came across this repo. However, I wanted to execute this functionality from Go package and not as part of protoc command. Would you consider exposing the "internal/converter" package so that it's can be consumed programatically by others?

Thanks, Jay.

chrusty commented 1 year ago

Hi @k-jay-c, thanks for your interest in the project.

On the face of it this is a reasonable request - I have no additional interest in forcing people to use the protoc toolchain... this project just went that way because it was the use case I had at the time.

Regarding exposting that package directly however, I'm not sure it is such a good idea. That package is pretty ugly and things often change in there to solve new problems (or fix historical issues). The reason it is under /internal now is because that really says "functions within this package may change in ways that will break your code if you were to import it".

However, a solution could be to maintain a publicly importable interface under /pkg which takes care of all that. It just means that I can safely keep working on the converter package, while presenting public methods in a controlled way.

There are also some technical considerations here. Currently protoc does take care of quite a lot for us - it reads and interprets the *.proto files, then presents them to the converter as a neatly packaged request. I'm not sure how easy it would be to replicate that behaviour. The Protobuf tools aren't written in Go, so I can't just import their libraries and make use of them (this is why the unit tests for this project actually require the protoc binary to be present - it is used to prepare the conversion requests each time).

Let me know if you have any thoughts on how this could be done, or how you would like to interact with such a package.

k-jay-c commented 1 year ago

Hi @chrusty,

Thank you very much for getting back so quickly. With regards to having a publicly importable /pkg, that would be great.

With regards to technical considerations - I'm afraid I have very little knowledge of the internals of protoc and how it's operating. I have however used go libraries that parses proto file and provides the file descriptors which I use for further processing. Please see link here. I'm wondering if something like this can be used? Or the API accepts FileDescriptor array that is pre-parsed and the library works with that?

chrusty commented 1 year ago

Hi @k-jay-c. I've had a good hunt around, but at this time I'm unable to find a suitable way to load these files in the way I need for this to work.

I will of course keep this in mind in future, if I happen to find something that will work.