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

Support JSON wire format for well-known types #571

Closed
oyvindwe opened this issue May 23, 2022 · 2 comments
Closed

Support JSON wire format for well-known types #571

oyvindwe opened this issue May 23, 2022 · 2 comments

Comments

@oyvindwe
Copy link
Collaborator

We have a webapp for a gRPC backend with a lot of types. In our scenario, using fromPartial is not desired, as this would add thousands of lines to our webapp client. Instead we are maintaining a fork of ts-proto that generates types that can be sent and received directly over HTTP, but over time several of the changes we have made in our fork have been included as various options, so we are now trying to move to vanilla ts-proto. The support is 90% in place using the following options:
forceLong=string,env=browser,useOptionals=all,outputEncodeMethods=false,outputJsonMethods=false,outputClientImpl=false,onlyTypes=true,stringEnums=true,useDate=string

However, we struggle with support for some well known types, e.g.:

We considered supporting Duration by adding string as a type alias, but for FieldMask the original type is lost.

For us it would make sense to add an option to generate types that are directly compatible with the JSON representation of well-known types. We are happy to provide a PR for this, but we would like some feedback on the idea before putting in the effort.

@oyvindwe oyvindwe changed the title Support wire format for well-known types Support JSON wire format for well-known types May 23, 2022
@stephenh
Copy link
Owner

@oyvindwe ah sure, that sounds like a good idea. I was initially a little hesitant b/c our well-known types support is good but also pretty complicated, but I think what you're asking only touch the "types only" output, so hopefully not too be too bad. A PR would be great!

@oyvindwe
Copy link
Collaborator Author

oyvindwe commented Jun 1, 2022

I think what you're asking only touch the "types only" output, so hopefully not too be too bad.

That was s good point, so I made the new option requiring onlyTypes=true, which made the change very simple.

A PR would be great!

Done! :)

stephenh pushed a commit that referenced this issue Jun 2, 2022
* New option 'useJsonWireFormat'. Fixes issue #571

* Added test.

* Formatting.
stephenh pushed a commit that referenced this issue Jun 2, 2022
# [1.115.0](v1.114.7...v1.115.0) (2022-06-02)

### Features

* added option 'useJsonWireFormat' ([#576](#576)) ([a71b145](a71b145)), closes [#571](#571)
@oyvindwe oyvindwe closed this as completed Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants