Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple options with same name not parsed correctly #1352

Open
rok-povsic opened this issue Jan 23, 2020 · 1 comment
Open

Multiple options with same name not parsed correctly #1352

rok-povsic opened this issue Jan 23, 2020 · 1 comment

Comments

@rok-povsic
Copy link

rok-povsic commented Jan 23, 2020

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
@eyalpost
Copy link
Contributor

eyalpost commented Feb 3, 2020

I believe this is a duplicate of #1329
A PR is waiting for 6 months now to be approved :-( #1256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants