microsoft / typespec

https://typespec.io/
MIT License
4.12k stars 198 forks source link

[Feature request] [protobuf] add optional keyword #4311

Open w01fgang opened 2 weeks ago

w01fgang commented 2 weeks ago

Clear and concise description of the problem

There's no way to add optional keyword for protobuf. The optional keyword behaviour is not always the same and depend from the client language as well. For example Go client has an option that defines the optional keyword behaviour. 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.

In this definition User has ordersCount that required in the api response and must have optional keyword to set default value to 0:

model User {
  @field(1)
  id: string;

  @field(10)
  address?: Address;

  @optional // this is not implemented yet
  @field(11)
  ordersCount: int32 = 0;
}

Checklist

markcowl commented 1 week ago

investigation