grpc-ecosystem/grpc-gateway

Generating Multiple Path Bindings for Single gRPC Call

Ouverte

#720 ouverte le 9 août 2018

 (42 commentaires) (6 réactions) (0 personne assignée)Go (2 250 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (16 971 étoiles)
Métriques de merge PR
 (Merge moyen 8j 23h) (147 PRs mergées en 30 j)

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?

Guide contributeur