typespec icon indicating copy to clipboard operation
typespec copied to clipboard

respect optional fields in protobuf emitter

Open w01fgang opened this issue 1 year ago • 1 comments

Respect optional in protobuf emitter

The current implementation doesn't consider optionality of fields

model Test {
  @field(1)
  test?: boolean;
}

resulted in

message Test {
  bool test = 1;
}

This PR fixes this, so the output is as expected:

message Test {
  optional bool test = 1;
}

w01fgang avatar Aug 06 '24 19:08 w01fgang

@microsoft-github-policy-service agree

w01fgang avatar Aug 06 '24 20:08 w01fgang

Just had a call with our backend team, and this turns out to be more complex. The optional keyword behaviour is not always the same and depend from the client language as well. So this can be solved only with decorators because there's no constant connection between the open api optional filed definition and protobuf optional keyword presence. Closing it for now and will try to find the time to make it through decorators.

w01fgang avatar Aug 23 '24 10:08 w01fgang