Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

oneof fields are not supported as the "body"? #413

Closed
jmuk opened this issue Jun 16, 2017 · 1 comment · Fixed by #2739
Closed

oneof fields are not supported as the "body"? #413

jmuk opened this issue Jun 16, 2017 · 1 comment · Fixed by #2739

Comments

@jmuk
Copy link
Contributor

jmuk commented Jun 16, 2017

Hi,

Here's a short sample of proto input:

syntax = "proto3";

package foo;

import "google/api/annotations.proto";
import "google/protobuf/struct.proto";

service FooService {
  rpc foo(FooRequest) returns (FooResponse) {
    option (google.api.http) = {
      post: "/foo-message"
      body: "msg"
      additional_bindings: {
        post: "/foo-struct"
        body: "str"
      };
    };
  }
}

message FooRequest {
  oneof payload {
    string msg = 1;
    google.protobuf.Struct str = 2;
  }
}

message FooResponse {}

It successfully generates the pb.gw.go file, but go build fails as:

./foo.pb.gw.go:40: protoReq.Msg undefined (type FooRequest has no field or method Msg)
./foo.pb.gw.go:61: protoReq.Str undefined (type FooRequest has no field or method Str)

The related line looks like:

if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Msg); err != nil {

The generated go type has the name of field as Payload (the name of oneof) rather than individual oneof names, and that field accepts FooRequest_Msg or FooRequest_Str type. Maybe the codegen can't deal with oneof fields in the body parameter?

yugui added a commit that referenced this issue Jun 17, 2017
yugui added a commit that referenced this issue Jun 17, 2017
abronan pushed a commit to abronan/grpc-gateway that referenced this issue Mar 7, 2018
@tmc
Copy link
Collaborator

tmc commented Jun 19, 2018

See #570

# for free to join this conversation on GitHub. Already have an account? # to comment