stephenh / ts-proto

An idiomatic protobuf generator for TypeScript
Apache License 2.0
2.12k stars 344 forks source link

Support `google.api` attributes/conventions #1019

Open jenia opened 6 months ago

jenia commented 6 months ago

Hello.

I want to use google.api.field_behavior as so:

import "proto/googleapis/google/api/field_behavior.proto";
message PersonRequest {
  string query = 1 [(google.api.field_behavior) = REQUIRED];
  int32 page_number = 2;
  int32 results_per_page = 3;
  string name3 = 4 [(google.api.field_behavior) = OPTIONAL];
}

But instead of compiling name3 to name3?: string I see:

export interface PersonRequest {
  query: string;
  pageNumber: number;
  resultsPerPage: number;
  name3: string;
}

Here is how I compile the protocol buffer:

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto \
-I. \
--ts_proto_out=./src \
./proto/person.proto

Anyone knows how to use google.api.field_behavior with ts_proto?

stephenh commented 6 months ago

Hi @jenia ; ts-proto doesn't currently support the various google.api-* attributes. Afaiu they are not really a part of core protobuf behavior, and instead a set of conventions that google-specific services (or google-style APIs) have adopted.

It is fairly unlikely we'll support this, unless a contributor steps up to flush it out & own this functionality long-term. If you're interested, that'd be great! Thanks!