-
Notifications
You must be signed in to change notification settings - Fork 52
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
Inconsistent Well-Known Types handling with grpc-gateway #25
Comments
alright, looking at the mapping in this page again. looks like timestamp needs to be mapped to proper date string format on the wire. Ideally putting the Date type in the generated field will be fit. However translating it back from the wire will become the essence of this piece of work. @lixin9311 |
Couldn't we leave the "translating it back from the wire" to the client (end-user using the library)? |
there will be annoying type mismatch if we don't do it in the plugin |
I see, but I think Let me know if my understanding is correct 🙏🏼 |
I'm not very good at Typescript. But I think we might have to define a customized type for those, or just leave them as strings for now. Some refs: |
|
I've been trying to figure out a solution for a week. But I see no other way than using class definitions (with customized methods) or extra helper functions instead of just plain types. There could be huge API change if switch to class, and other issues (OneOf implementation). |
well I believe there are still ways to get around this without using class and the keep the simplicity of using POJOs. I'll give it a try later on when I'm freed up a bit more. |
I don't really understand the reasoning behind the complexity yet. As far as I can tell, this plugin doesn't do any transformations on the JSON, and just passes everything straight through to the client. Why start with this complexity now, instead of just adding a Not that a Date wouldn't be convenient, but I'm not sure if it's worth the extra complexity. (And break backwards compatibility) |
@lyonlai Were you able to get this working? Would it be possible to upstream this change cresta@65941a4? |
Is this repo still maintained? |
@lyonlai I can work on this if you give me the general direction. I already made a patch before. |
Any updates on this issue? I have the same trouble but with |
Previously discussed in #4
Although we should run most other protoc plugins with WKT definitions come with the protoc (
timestamp.pb
,duration.pb
etc.).In the case of
protoc-gen-grpc-gateway-ts
, we should generate TypeScript definitions compatible with grpc-gateway's JSON mapping (andprotoc-gen-openapiv2
).Currently, by running the
protoc-gen-grpc-gateway-ts
ontimestamp.pb
, we will get the underlying definition of the timestamp.Which will be rejected by grpc-gateway.
The correct JSON mapping of the timestamp is a datetime in RFC3339(nano) format, which can be fulfilled by the default behavior of JSON.stringify a Date object in JavaScript.
I think we still need to set up exception rules for parsing those WKTs, at least for Timestamp and Duration.
atreya2011@a1e3d5c seems to be a good patch without the handling of wrappers, duration and etc.
The text was updated successfully, but these errors were encountered: