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

Support wrapper types #20

Merged
merged 4 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
WORKDIR := $(shell mkdir -p $(PWD)/.work && mktemp -d "$(PWD)/.work/tmp.XXX")

DOCKER ?= docker
PROTOC_DOCKER_IMAGE ?= thethingsindustries/protoc:3.0.23
PROTOC_DOCKER_IMAGE ?= thethingsindustries/protoc:3.0.24
PROTOC_DOCKER_ARGS := run --user `id -u` --rm \
--mount type=bind,src=$(PWD),dst=$(PWD) \
-e IN_TEST \
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ require (
github.com/golang/protobuf v1.2.0
github.com/kr/pretty v0.1.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pseudomuto/protokit v0.0.0-20181108154750-3705a628937f
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d
github.com/stretchr/testify v1.2.2 // indirect
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI=
Expand All @@ -15,9 +16,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pseudomuto/protokit v0.0.0-20181108154750-3705a628937f h1:wUWNbuwHlOhNw32XWuL7TbJHIkHJo90trrPAyTc/QFQ=
github.com/pseudomuto/protokit v0.0.0-20181108154750-3705a628937f/go.mod h1:2PdH30hxVHsup8KpBTOXTBeMVhJZVio3Q8ViKSAXT0Q=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY=
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
78 changes: 69 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ import (
const FileHeader = `// Code generated by protoc-gen-fieldmask. DO NOT EDIT.`

const (
protoAnyType = ".google.protobuf.Any"
protoDurationType = ".google.protobuf.Duration"
protoEmptyType = ".google.protobuf.Empty"
protoFieldMaskType = ".google.protobuf.FieldMask"
protoStructType = ".google.protobuf.Struct"
protoTimestampType = ".google.protobuf.Timestamp"
protoAnyType = ".google.protobuf.Any"
protoBoolValueType = ".google.protobuf.BoolValue"
protoBytesValueType = ".google.protobuf.BytesValue"
protoDoubleValueType = ".google.protobuf.DoubleValue"
protoDurationType = ".google.protobuf.Duration"
protoEmptyType = ".google.protobuf.Empty"
protoFieldMaskType = ".google.protobuf.FieldMask"
protoFloatValueType = ".google.protobuf.FloatValue"
protoInt32ValueType = ".google.protobuf.Int32Value"
protoInt64ValueType = ".google.protobuf.Int64Value"
protoStringValueType = ".google.protobuf.StringValue"
protoStructType = ".google.protobuf.Struct"
protoTimestampType = ".google.protobuf.Timestamp"
protoUInt32ValueType = ".google.protobuf.UInt32Value"
protoUInt64ValueType = ".google.protobuf.UInt64Value"
)

type unknownTypeError string
Expand Down Expand Up @@ -143,7 +152,22 @@ func appendPaths(paths []string, prefix string, md *protokit.Descriptor, mdMap m
fmd, ok := mdMap[fd.GetTypeName()]
if !ok {
switch fd.GetTypeName() {
case protoTimestampType, protoFieldMaskType, protoDurationType, protoStructType, protoEmptyType, protoAnyType:
case protoAnyType,
protoBoolValueType,
protoBytesValueType,
protoDoubleValueType,
protoDurationType,
protoEmptyType,
protoFieldMaskType,
protoFloatValueType,
protoInt32ValueType,
protoInt64ValueType,
protoStringValueType,
protoStructType,
protoTimestampType,
protoUInt32ValueType,
protoUInt64ValueType:

delete(seen, fd.GetFullName())
continue
}
Expand Down Expand Up @@ -280,9 +304,17 @@ func goFieldOf(fd *protokit.FieldDescriptor) goField {
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "Any"

case protoStructType:
case protoBoolValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "Struct"
typ.Name = "BoolValue"

case protoBytesValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "BytesValue"

case protoDoubleValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "DoubleValue"

case protoEmptyType:
typ.Pkg = "github.com/gogo/protobuf/types"
Expand All @@ -292,6 +324,34 @@ func goFieldOf(fd *protokit.FieldDescriptor) goField {
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "FieldMask"

case protoFloatValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "FloatValue"

case protoInt32ValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "Int32Value"

case protoInt64ValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "Int64Value"

case protoStringValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "StringValue"

case protoStructType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "Struct"

case protoUInt32ValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "UInt32Value"

case protoUInt64ValueType:
typ.Pkg = "github.com/gogo/protobuf/types"
typ.Name = "UInt64Value"

default:
typ.SetFielder = true
typ.Name = fd.GetTypeName()
Expand Down
7 changes: 7 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestFieldMaskPaths(t *testing.T) {
"a.a.testNestedNestedOneOf",
"a.a.testNestedNestedOneOf.e",
"a.a.testNestedNestedOneOf.f",
"a.a.testNestedNestedOneOf.g",
"a.b",
"a.c",
"a.d",
Expand All @@ -156,6 +157,7 @@ func TestFieldMaskPaths(t *testing.T) {
"b.a.testNestedNestedOneOf",
"b.a.testNestedNestedOneOf.e",
"b.a.testNestedNestedOneOf.f",
"b.a.testNestedNestedOneOf.g",
"b.b",
"b.c",
"b.d",
Expand All @@ -169,11 +171,13 @@ func TestFieldMaskPaths(t *testing.T) {
"c.a.testNestedNestedOneOf",
"c.a.testNestedNestedOneOf.e",
"c.a.testNestedNestedOneOf.f",
"c.a.testNestedNestedOneOf.g",
"c.b",
"c.c",
"c.d",
"c.e",
"g",
"h",
"testOneof",
"testOneof.d",
"testOneof.e",
Expand All @@ -184,6 +188,7 @@ func TestFieldMaskPaths(t *testing.T) {
"b",
"c",
"g",
"h",
"testOneof",
})

Expand All @@ -196,6 +201,7 @@ func TestFieldMaskPaths(t *testing.T) {
"a.testNestedNestedOneOf",
"a.testNestedNestedOneOf.e",
"a.testNestedNestedOneOf.f",
"a.testNestedNestedOneOf.g",
"b",
"c",
"d",
Expand All @@ -217,6 +223,7 @@ func TestFieldMaskPaths(t *testing.T) {
"testNestedNestedOneOf",
"testNestedNestedOneOf.e",
"testNestedNestedOneOf.f",
"testNestedNestedOneOf.g",
})
a.So(testdata.Test_TestNested_TestNestedNestedFieldPathsTopLevel, should.Resemble, []string{
"a",
Expand Down
28 changes: 28 additions & 0 deletions testdata/testdata.pb.fm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading