Describe the bug
@message
model ChatBase {
@field(1) username: string;
@field(2) first_name?: string;
@field(3) last_name?: string;
@field(4) id: int64;
@field(5) createdAt: Time;
}
Generating wrong proto3 schema:
message ChatBase {
string username = 1;
string first_name = 2;
string last_name = 3;
int64 id = 4;
int64 createdAt = 5;
}
Expected result according to proto3
docs: https://protobuf.dev/programming-guides/proto3/#field-labels
message ChatBase {
string username = 1;
optional string first_name = 2;
optional string last_name = 3;
int64 id = 4;
int64 createdAt = 5;
}
Yes, by design all properties in proto3 are optional (like in Go way: Optional of string is = "")
But sometimes we wanna know when the property was explicitly set:
message Person {
int64 age = 1; // when default it'll be 0, but there's some 0 age people in the planet :)
}
message Person {
optional int64 age = 1; // OK, it's just not set, not overlapsing with 0 age people
}
Reproduction
https://typespec.io/playground/?e=%40typespec%2Fprotobuf&c=aW1wb3J0ICJAdHlwZXNwZWMvcHJvdG9idWYiOwoKdXNpbmcgUMcSOwoKQMgMLmBwYWNrYWdlYCh7CiAgbmFtZTogIkV4YW1wbGUiCn0pCsQTc3BhY2UgZcYWxD9tZXNzYWdlCm1vZGVsIENoYXRCYXNlIMRDICBAZmllbGQoMSkgdXNlcsZTc3RyaW5nO8wgMikgZmlyc3RfxCI%2F1SMzKSBsYd0iNCkgaWQ6IGludDY0zRk1KSBjcmVhdGVkQXQ66QD7LldlbGxLbm93bi5UaW1lc3RhbXA7Cn0K&options=%7B%7D&vs=%7B%7D
Checklist
Describe the bug
Generating wrong proto3 schema:
Expected result according to proto3
docs: https://protobuf.dev/programming-guides/proto3/#field-labels
Yes, by design all properties in proto3 are optional (like in Go way: Optional of string is = "")
But sometimes we wanna know when the property was explicitly set:
Reproduction
https://typespec.io/playground/?e=%40typespec%2Fprotobuf&c=aW1wb3J0ICJAdHlwZXNwZWMvcHJvdG9idWYiOwoKdXNpbmcgUMcSOwoKQMgMLmBwYWNrYWdlYCh7CiAgbmFtZTogIkV4YW1wbGUiCn0pCsQTc3BhY2UgZcYWxD9tZXNzYWdlCm1vZGVsIENoYXRCYXNlIMRDICBAZmllbGQoMSkgdXNlcsZTc3RyaW5nO8wgMikgZmlyc3RfxCI%2F1SMzKSBsYd0iNCkgaWQ6IGludDY0zRk1KSBjcmVhdGVkQXQ66QD7LldlbGxLbm93bi5UaW1lc3RhbXA7Cn0K&options=%7B%7D&vs=%7B%7D
Checklist