grpc-ecosystem/grpc-gateway

Generating Multiple Path Bindings for Single gRPC Call

Aperta

#720 aperta il 9 ago 2018

 (42 commenti) (6 reazioni) (0 assegnatari)Go (2250 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (16.971 stelle)
Metriche merge PR
 (Merge medio 8g 23h) (147 PR mergiate in 30 g)

Descrizione

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?

Guida contributor