Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

oneof parameter in path generated code missing package #2042

Open
elvizlai opened this issue Mar 17, 2021 · 2 comments
Open

oneof parameter in path generated code missing package #2042

elvizlai opened this issue Mar 17, 2021 · 2 comments

Comments

@elvizlai
Copy link

@elvizlai elvizlai commented Mar 17, 2021

🐛 Bug Report

To Reproduce

package api.svc;

option go_package = "api/svc";

  rpc GetTrieNode(api.infra.GetTrieNodeReq) returns (api.infra.KVNode) {
    option (google.api.http) = {
      post: "/trie/node:get"
      body: "*"
      additional_bindings {
        get: "/trie/node/{id}"
      }
      additional_bindings {
        get: "/trie/node/path/{path}"
      }
    };
  }
package api.infra;

option go_package = "api/infra";

message GetTrieNodeReq {
  oneof x {
    string id   = 1;
    string path = 2;
  }
}

Expected behavior

*GetTrieNodeReq_Id should has pkg prefix *infra.GetTrieNodeReq_Id

Actual Behavior

	if protoReq.X == nil {
		protoReq.X = &GetTrieNodeReq_Id{}
	} else if _, ok := protoReq.X.(*GetTrieNodeReq_Id); !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *GetTrieNodeReq_Id, but: %t\n", protoReq.X)
	}
	protoReq.X.(*GetTrieNodeReq_Id).Id, err = runtime.String(val)
	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
	}

Your Environment

./protoc-gen-grpc-gateway -version
Version 2.3.0, commit bcc34ef50bda81faae5d4bbfca2e7ea8fe4700c8, built at 2021-02-25T18:32:39Z
@elvizlai
Copy link
Author

@elvizlai elvizlai commented Mar 18, 2021

The key point maybe

if c.Target.ForcePrefixedName {
oneofFieldName = msg.File.Pkg() + "." + oneofFieldName
}

@johanbrandhorst
Copy link
Collaborator

@johanbrandhorst johanbrandhorst commented Mar 19, 2021

Hi Yongzheng, thanks for the bug report! This does indeed look like a bug, and we should try to fix it :). I see you've already done a bit of digging, the first step to submitting a fix would be to try and produce a failing test. I would try to look at the existing tests in https://github.com/grpc-ecosystem/grpc-gateway/blob/9814f850088dcaaa6018446a366d8337f396aacb/internal/descriptor/types_test.go and see if any can be copied and adapted to reproduce your bug, and then we can start iterating on a fix for it. How does that sound?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants