Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom type/file "registries" to WithProtoJSON #788

Closed
ppacher opened this issue Oct 13, 2024 · 3 comments
Closed

Add support for custom type/file "registries" to WithProtoJSON #788

ppacher opened this issue Oct 13, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ppacher
Copy link

ppacher commented Oct 13, 2024

Is your feature request related to a problem? Please describe.

I'm working a lot with google/protobuf/any.proto and also created some kind of "descriptor-lookup" service pbtype-server. While retrieving FileDescriptor works pretty well I needed to copy&paste the protoJsonCodec to support a custom resolver.

Describe the solution you'd like

It would be awesome to extend the current WithProtoJSON to accept a custom type and message resolver.

Describe alternatives you've considered
Copy & paste the current protoJsonCodec implementation and add support to configure the type resolver.

Solution

Before:

path, handler := expamlev1connect.NewExampleClient(
    http.DefaultClient,
    url,
)

After:

path, handler := expamlev1connect.NewExampleClient(
    http.DefaultClient,
    url,
    connect.WithProtoJsonRegistry( myCustomerTypeResolver{} )
)

The interface should enforce implementation of either linker.Resolver or, if not required, protoreflect.MessageTypeResolver and protoreflect.ExtensionTypeResolver at least.

For example:

I'd like to propose a PR but wanted to ask for feedback before!

@ppacher ppacher added the enhancement New feature or request label Oct 13, 2024
@bufdev
Copy link
Member

bufdev commented Oct 13, 2024

Thanks for the proposal. I don't think this is something we'd accept in the mainline repository - this seems like a perfect case to maintain your own Codec. We want to keep this library as lean as possible, and your extension for your advanced use case should live in your repository.

@bufdev bufdev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2024
@jhump
Copy link
Member

jhump commented Oct 15, 2024

@ppacher, FWIW, there is a third-party library you could use to do this, created by one of the authors of connect-go: https://github.com/akshayjshah/connectproto
It allows you to create a codec where you can set the Resolver field in the protojson.MarshalOptions, protojson.UnmarshalOptions, and proto.UnmarshalOptions structs.

@ppacher
Copy link
Author

ppacher commented Oct 15, 2024

@bufdev, @jhump , thanks for the response!

While I understand that you want to keep the lib as lean as possible I still think that the addition of a WithProtoJSONOptions( WithResolver(...)) wouldn't blow up the API surface to much and while still preserving backward comptability. Though, if this is out of scope for connect-go I'll accept it and try the mentioned solution from @jhump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants