grpc-ecosystem / protoc-gen-grpc-gateway-ts

protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript clients that connect the web frontend and golang backend fronted by grpc-gateway.
Apache License 2.0
142 stars 51 forks source link

Add optional fields support #21

Open vgarvardt opened 3 years ago

vgarvardt commented 3 years ago

As of protobuf 3.15 optional fields are available, but they are not supported by the generator:

test/optional/v1/has_optional_field.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-grpc-gateway-ts hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--grpc-gateway-ts_out:

test/optional/v1/has_optional_field.proto contents:

syntax = "proto3";

package test.optional.v1;

message HasOptionalField {
  string not_optional = 1;
  optional string not_required = 2;
}
lyonlai commented 3 years ago

haven't run into this before. let me have a look and get back to you later.

lyonlai commented 3 years ago

👋 @vgarvardt getting around the error itself is simple. But that doesn't mean the output code will have full support of the optional semantic in proto3. So I don't think it's the right thing to do.

The current situation is that the support of proto2 optional/require is not properly implemented in this generator. To achieve the real support of optional field in proto3, might as well solve the proto2 problem at the same time. So there will be quite a bit of work needs to be done.

vgarvardt commented 3 years ago

I'm still very interested in this and may spend some time helping with the implementation, but I'll need your guidance. Maybe you can describe the job that needs to be done for a proper implementation, or at least the first steps so I could try to work on it and let you review PRs if you do not have to work on it.

yinheli commented 3 years ago

@vgarvardt I just let optional enable to generate, but not implements, refer: https://github.com/yinheli/protoc-gen-grpc-gateway-ts/commit/bb766c2d072ebc800aaac902add2c330a27bca72

lyonlai commented 3 years ago

yup, what @yinheli suggested will unblock you for now. @vgarvardt. I was gonna start working on it but got distracted to other priorities. Free free to start thinking about it before the implementation. I'll guide you through

ergoz commented 2 years ago

any updates? It will make usable this generator. It is really sucks to use grpc-web instead....

theartofdevel commented 2 years ago

any updates?

KubeKyrie commented 1 year ago

any updates?