Incorrect error message when execute protoc-gen-grpc-gateway to HTTP GET method with BODY #531
Description
I try to compile by protoc-gen-grpc-gateway the below definition to generate reverse-proxy file.
service TaskManager {
rpc GetTask (GetTaskRequest) returns (Task) {
option (google.api.http) = {
get: "/v1/tasklist-gateway/task/{id}" // "id" is defined in GetTaskRequest
body: "*"
};
}
}
message GetTaskRequest {
int32 id = 1;
}
protoc returns error with below text.
needs request body even though http method is GET: GetTask
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. proto/task_list.proto
--grpc-gateway_out: needs request body even though http method is GET: GetTask
However, solution for the error is remove body statement.
rpc GetTask (GetTaskRequest) returns (Task) {
option (google.api.http) = {
get: "/v1/tasklist-gateway/task/{id}" // "id" is defined in GetTaskRequest
};
}
I think HTTP GET request should not include BODY. It it correct error text?
Detail
Related implementation codes are below.
grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go
Lines 75 to 79 in 5e029d0
case opts.GetGet() != "":
httpMethod = "GET"
pathTemplate = opts.GetGet()
if opts.Body != "" {
return nil, fmt.Errorf("needs request body even though http method is GET: %s", md.GetName())
}
It seems "if statement" validates that request body has no string, but error text is recommending set the request body. Also, I think DELETE method has same issue.
grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go
Lines 89 to 94 in 5e029d0
case opts.GetDelete() != "":
httpMethod = "DELETE"
pathTemplate = opts.GetDelete()
if opts.Body != "" && !r.allowDeleteBody {
return nil, fmt.Errorf("needs request body even though http method is DELETE: %s", md.GetName())
}
And, I created below pull request for this issue.
#532
I would appreciate it if you could check this issue, and PR.