-
Notifications
You must be signed in to change notification settings - Fork 599
-
Hello, I am trying to parse a existing proto file in my local. And add some new code for eg:
syntax = "proto3";
package xx.stations.proto;
import "xx/stations/proto/wrappers.proto";
option java_multiple_files = true;
option java_package = "com.xx.stations.grpc.service";
option java_outer_classname = "StationsInternalApiV1Proto";
option objc_class_prefix = "STATIONS";
service StationsInternalApiV1 {
rpc addStationToCollection (ListenerReq) returns (SuccessResponse) {}
to be changed as
syntax = "proto3";
package xx.stations.proto;
import "xx/stations/proto/wrappers.proto";
option java_multiple_files = true;
option java_package = "com.xx.stations.grpc.service";
option java_outer_classname = "StationsInternalApiV1Proto";
option objc_class_prefix = "STATIONS";
service StationsInternalApiV1 {
rpc addStationToCollection (ListenerReq) returns (SuccessResponse) {
option (google.api.http) = {
post: "/addStationToCollection"
body: "*"
};
}
I need to add this change all the method calls within the proto file. However instead of doing it manually. I would like to introduce code generation. I was wondering if I can use wire-schema in order to read the proto file and make changes to it through of any of the library classes. Please let me know.
Beta Was this translation helpful? Give feedback.
All reactions
That should be simple yes.
You don't even have to build the Schema, you could manipulate the parsed file directly.
Parse it with ProtoParser, you mutate the types you want, you could be iterating all ProtoFileElement#services, add the option you need or whatever change you wanna do, and reprint the protos with ProtoFileElement.toSchema().
Replies: 1 comment 2 replies
-
That should be simple yes.
You don't even have to build the Schema, you could manipulate the parsed file directly.
Parse it with ProtoParser, you mutate the types you want, you could be iterating all ProtoFileElement#services, add the option you need or whatever change you wanna do, and reprint the protos with ProtoFileElement.toSchema().
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you, I was just able to find it. What's the parameter "data" represent. I understand location takes in the location of the protofile. What is data about?
Beta Was this translation helpful? Give feedback.
All reactions
-
data is the content of the file.
You can otherwise try to use SchemaLoader. Look at the code or where it's used and you should be able to go.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1