-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
protobuf.js version: 6.8.8
HTTP endpoint options in grpc-gateway can have multiple options with the same name, see an example here.
Such options aren't parsed correctly by Protobuf.js, since, when iterating through them, it uses a key-value structure, resulting in only one of the additional_bindings
field that is actually returned to the user (that is, the last one).
A small example:
// abc.proto
import "google/api/annotations.proto";
message ProtoA {}
message ProtoB {}
service TestService {
rpc RpcBodyRpc(ProtoA) returns (ProtoB) {
option (google.api.http) = {
post: "/url1"
body: "*"
additional_bindings {
post: "/url2"
}
additional_bindings {
post: "/url3"
}
};
}
}
const Protobuf = require("protobufjs");
const methods = new Protobuf.Root().loadSync("abc.proto").nested.TestService.methods;
for (const methodName in methods) {
if (!methods.hasOwnProperty(methodName)) continue;
const options = methods[methodName].options;
for (const fieldName in options) {
console.log(fieldName + ": " + options[fieldName]);
}
}
This prints the following (note it's missing /url2
):
(google.api.http).post: /url1
(google.api.http).body: *
(google.api.http).additional_bindings.post: /url3
Metadata
Metadata
Assignees
Labels
No labels