protoc-gen-typescript-http icon indicating copy to clipboard operation
protoc-gen-typescript-http copied to clipboard

fix(type): Correctly map proto to json according to spec

Open paulip1792 opened this issue 3 years ago • 4 comments

In protobuf definition (https://developers.google.com/protocol-buffers/docs/proto3#json), 64 bits numeric types should be interpreted as string in JSON.

paulip1792 avatar Aug 04 '22 07:08 paulip1792

Hello @paulip1792, thanks for contributing. I ran the CI pipeline, and youre missing the changes to generated code in your commit.

For my understand have you seen any isues with the current mapping in your applications?

ericwenn avatar Aug 04 '22 08:08 ericwenn

@ericwenn I am using protojson (https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson) to marshal the response and 64 bits integer will be quoted as string value. I guess it's because JS Number can only represent 53 bits integer, so it's defined as string in the spec. In my opinion, in order to make sure it's all type-safe, 64 bits integer should be represented in string. I will make the CI happy if it is accepted change since I know it's a breaking change.

paulip1792 avatar Aug 04 '22 11:08 paulip1792

I agree we should address this. As it turns out we rarely use int64 in our protobuf schemas, so that is likely why we have not noticed it.

Thanks for the PR and reading through the spec!

ericwenn avatar Aug 04 '22 12:08 ericwenn

@paulip1792 Is this still something you want to work on fixing?

ericwenn avatar Aug 31 '22 11:08 ericwenn