Skip to content

Multiple options with same name not parsed correctly #1352

@rok-povsic

Description

@rok-povsic

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions