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

protoc-gen-swagger throws the error: Any JSON doesn't have '@type' #771

Closed
yangliCypressTest opened this issue Oct 9, 2018 · 8 comments
Closed

Comments

@yangliCypressTest
Copy link

I defined a message which includes the 'google.protobuf.Any' type

message TestRequest {
int64 id = 1;
google.protobuf.Any items = 2;
}
and generate the related pb.gw.go file, and when to execute below auto-gen code, it failed with the error: Any JSON doesn't have '@type'
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}

@johanbrandhorst
Copy link
Collaborator

Curious, this definitely should be working, what does the JSON that it's trying to unmarshal look like?

@yangliCypressTest
Copy link
Author

The struct of TestRequest is like below one, it is auto-generated.

type TestRequest struct {
Id int64 protobuf:"varint,1,opt,name=id" json:"id,omitempty"
Items *google_protobuf1.Any protobuf:"bytes,2,opt,name=items" json:"items,omitempty"
}

@johanbrandhorst
Copy link
Collaborator

What does the JSON input look like?

@yangliCypressTest
Copy link
Author

yangliCypressTest commented Oct 9, 2018

Pass below through request' body, @johanbrandhorst
{
"items": {
"include": [{"id": 3, "test_name": "Test_Value"}]
}

}

@johanbrandhorst
Copy link
Collaborator

Yeah so you haven't specified the type URL in the JSON input. Please see documentation for the google.protobuf.Any type to see how to use it with JSON. This is not a bug.

@yangliCypressTest
Copy link
Author

Sorry, I didn't find any official example from documentation, could you please supply one for me to refer to? thx @johanbrandhorst

@johanbrandhorst
Copy link
Collaborator

https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto#L94

@yangliCypressTest
Copy link
Author

thx

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

No branches or pull requests

2 participants