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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions internal/plugin/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,27 @@ func typeFromField(pkg protoreflect.FullName, field protoreflect.FieldDescriptor
}
}

// JSON Mapping: https://developers.google.com/protocol-buffers/docs/proto3#json
func namedTypeFromField(pkg protoreflect.FullName, field protoreflect.FieldDescriptor) Type {
switch field.Kind() {
case protoreflect.StringKind, protoreflect.BytesKind:
case
protoreflect.StringKind,
protoreflect.BytesKind,
protoreflect.Int64Kind,
protoreflect.Uint64Kind,
protoreflect.Fixed64Kind,
protoreflect.Sfixed64Kind,
protoreflect.Sint64Kind:
return Type{IsNamed: true, Name: "string"}
case protoreflect.BoolKind:
return Type{IsNamed: true, Name: "boolean"}
case
protoreflect.Int32Kind,
protoreflect.Int64Kind,
protoreflect.Uint32Kind,
protoreflect.Uint64Kind,
protoreflect.DoubleKind,
protoreflect.Fixed32Kind,
protoreflect.Fixed64Kind,
protoreflect.Sfixed32Kind,
protoreflect.Sfixed64Kind,
protoreflect.Sint32Kind,
protoreflect.Sint64Kind,
protoreflect.FloatKind:
return Type{IsNamed: true, Name: "number"}
case protoreflect.MessageKind:
Expand Down