utrack / clay

Proto-first minimal server platform for gRPС+REST+Swagger APIs
MIT License
289 stars 39 forks source link

Proto type int64 get the error format in http swagger post body #91

Closed zengzhengrong closed 4 years ago

zengzhengrong commented 4 years ago

proto file

message Userprofile{
  int64 user_id = 1;
  ...
 }

pb.go

type Userprofile struct {
    UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
  ....
}

{8CE3E2BC-BF98-4D2F-BC36-BFE9087C216E}_20200616155100 It’s very strange ~, but I try to use int32 , it's work fine

utrack commented 4 years ago

Hi, it is not an error and in fact a Protobuf JSON mapping spec: https://developers.google.com/protocol-buffers/docs/proto3#json_mapping

It is done like that because JS integers are precise up to 2^52 instead of int64's 2^63: https://github.com/grpc-ecosystem/grpc-gateway/issues/219#issuecomment-251250029

So if you were sending JSON of {"foo":(number bigger than 2^52)} many JSON parsers won't parse that number.

bullgare commented 4 years ago

Yes, we've run into this limitation a couple of years ago also.

zengzhengrong commented 4 years ago

Thank ~! Got it