grpc-ecosystem/grpc-gateway

An RPC proto oneof field documents the field not used in the path as an optional request parameter

Open

#2494 opened on Jan 11, 2022

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Go (16,971 stars) (2,250 forks)batch import
buggood first issuehelp wantedopenapi

Description

Steps you follow to reproduce the error:

rpc GetArticle (GetArticleRequest) returns (GetArticleResponse) {
    option (google.api.http) = {
        get: "/v2/articles/{slug}"
        additional_bindings: {
            get: "/v2/articles/{id.hex}"
        }
     };
}

message GetArticleRequest {
    oneof article_id {
        insider.protobuf.ObjectID id = 1;
        string slug = 2;
    }
}

With the annotations above, two "separate" endpoints are defined in the output:

/v2/articles/{slug}
/v2/articles/{id.hex}

With the non-path parameter of the oneof listed as an optional query parameter, which is incorrect:

{
    "name": "id.hex",
    "description": "xyz",
    "in": "query",
    "required": false,
    "type": "string"
 }

What did you expect to happen instead:

I expect a single GET endpoint defined with 2 path parameters listed with oneof as required (not both, and nothing listed as a request parameter).

"parameters": [
  {
    "name": "slug",
    "description": "Article slug.",
    "in": "path",
    "required": true,
    "type": "oneof"
  },
  {
    "name": "id.hex",
    "description": "Article ID",
    "in": "path",
    "required": true,
    "type": "oneof"
  }
]

Your answer here.

What's your theory on why it isn't working:

I suspect there is simply no code to deal with the protobuf oneof type.

Contributor guide