-
Notifications
You must be signed in to change notification settings - Fork 35
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
protoc-gen-ng: implement support for optional fields in proto3 #54
Comments
Hi @johannesf95 nope, this old plugin generator is not anyhow something we should rely on. Of course it is better to migrate to one from google-protobuf. I tried it so far, looks pretty good, the migration went quite quickly; looks like the old lib was sticking very close to the original protobuf messages. Thank you very much for the time you took for the deep research! |
However, back to the original topic, question is, actually, whether there is a real need in optional parameters at all. Optional parameters is something related to the transport in the runtime, I guess. On the TypeScript side the optional parameters mean something entirely different. All the scalar values get their defaults anyway, in other words they can never be null / undefined. The only case where something can be optional is the non-repeated message field. Maybe it makes more sense to just have none of the optional fields at all, but the messages, and then respect this new flag in order to make them non-optional? |
Hi @smnbbrv, thanks for this fast reaction and the change to a more future proof dependency stack! I really appreciate this, since we recently decided to use ngx-grpc in an enterprise project. |
I will try to summarize first, the first target is to have the following (without complexity that is introduced by optional):
If the flag As I see from proto3 field presence definition there are also some changes to the serialization / deserialization. The further difference is that it affects the JSON output format ( This could be quite a big, definitely a breaking change. |
Implemented by #57 |
Hi, first of all thanks for this great library! It's easy to integrate and really works like a charm within angular. 👍
Since proto3 added support for optional fields per default recently protobuf v3.15.0, it would be great to reflect it inside the generated classes instead of declaring every field as optional. IMHO
printAsObjectMapping
andprintAsJSONMapping
in the fields generators should only print the?
, if the field is explicitly declared as optional in the proto3 definition.Additionally protoc throws this error currently, when trying to compile proto files with optional fields:
call.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-ng hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.
It seems like protoc-plugin is causing the error, because it includes an on old protobuf compiler and has not been updated for quite a while:
https://github.com/konsumer/node-protoc-plugin/blob/331e33f49565be967007f3d817e99a5a94fb8a30/src/google/protobuf/compiler/plugin_pb.js
Is it still necessary to rely on this dependency or would it make sense to use google-protobuf/google/protobuf/compiler/plugin_pb directly, like improbable-eng/ts-protoc-gen does?
The text was updated successfully, but these errors were encountered: