grpc-ecosystem/grpc-gateway

Generating Multiple Path Bindings for Single gRPC Call

Open

#720 opened on Aug 9, 2018

View on GitHub
 (42 comments) (6 reactions) (0 assignees)Go (2,250 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (16,971 stars)
PR merge metrics
 (Avg merge 8d 23h) (147 merged PRs in 30d)

Description

I have a field in a protobuf message called "parent". It looks like this:

message ListRolesRequest {
    // The resource name of the parent resource in one of the following formats:
    // `` (empty string) -- this refers to curated roles.
    // `organizations/{organization_id}`
    // `tenants/{tenant_id}`
    string parent = 1;
  ...
}

And a gRPC method that looks like this:

rpc ListRoles(ListRolesRequest) returns (ListRolesResponse) {
      option (google.api.http) = {
        get: "/auth/iam/roles"
        additional_bindings {
          get: "/auth/iam/{parent=organizations/*}/roles"
        }
        additional_bindings {
          get: "/auth/iam/{parent=tenants/*}/roles"
        }
      };
}

The parent can take the form organizations/<org_id> or tenants/<tenant_id> or it can be empty. I'd like the generated swagger definitions to match all three. For example:

GET /auth/iam/roles GET /auth/iam/organizations/<org_id>/roles GET /auth/iam/tenants/<tenant_id>/roles

The swagger generator currently only generates two paths:

GET /auth/iam/roles GET /auth/iam/{parent}/roles

{parent} only matches a single path parameter, and since the parent can include a slash you can't get a match.

What's the correct way of doing this?

Contributor guide