How can I get the lower snake case when using protoc to generate TypeScript from .proto definition files?
ddddwx opened this issue · comments
This is my .proto:
message Group {
uint32 id = 1;
uint32 project_id = 2;
string name = 3;
string descr = 4;
string state = 5;
int32 interval = 6;
google.protobuf.Struct attributes = 7;
repeated Page pages = 8;
}
I run the command: npx protoc --ts_out src/grpc/gen --ts_opt client_generic --proto_path src/grpc/proto src/grpc/proto/configuration_platform.proto
But I get the interface definition:
interface Group {
...
projectId: number;
...
}
It should be"project_id"
as same as definition in .proto
How could I fix my protoc command?
Many thanks.
It should be"project_id"as same as definition in .proto
Can you elaborate why it should be? It isn't with Protobuf for Go, Java, C#, PHP, or Dart.
It should be"project_id"as same as definition in .proto
Can you elaborate why it should be? It isn't with Protobuf for Go, Java, C#, PHP, or Dart.
This is how proto is defined. I need to unify to have proper front-end and back-end communication. Is "lower snake case" configurable? I didn't see the relevant configuration in the instruction manual.
If I use projectId, there is a server-error, projectId cannot be identified by server.
This is not how Protobuf is typically implemented - see the list of implementations above. Instead, the goal is to provide an API that is idiomatic to the target language. Peers can properly communicate regardless of property casing.
There is no plugin option to change the behavior.
I think @timostamm is getting his repos mixed up :) There is an option for this, see use_proto_field_name
:
By default interface fields use lowerCamelCase names by transforming proto field names to follow common style convention for TypeScript. Set this option to preserve original proto field names in generated interfaces.
Oof, I completely forgot about it 😅 Thanks for the shout, @jcready.
I think @timostamm is getting his repos mixed up :) There is an option for this, see
use_proto_field_name
:By default interface fields use lowerCamelCase names by transforming proto field names to follow common style convention for TypeScript. Set this option to preserve original proto field names in generated interfaces.
wow!!! It works!! Thank you very much for your help and detailed explanation. @jcready
Oof, I completely forgot about it 😅 Thanks for the shout, @jcready.
Thank you for providing this protoc tool. It's incredibly concise and user-friendly. I'm extremely grateful for it!
Thank you once again! @timostamm