protoc-gen-validate
protoc-gen-validate copied to clipboard
PGV is unable to import another generated go file in generated validator file
I have three proto files A.proto, B.proto and common.proto. I put some common messages between A and B into common.proto and I import it in A and B proto files. I use the below command to generate the go files:
protoc
-I example-grpc-spec
-I ${GOPATH}/src
-I ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate --go_out=plugins=grpc:$GOPATH/src
--validate_out=lang=go:$GOPATH/src example-grpc-spec/src/api/message/A/v1/A.proto
Also, I'm using go_package
to generate A.pb.go and A.pb.validate.go in a specific package. I defined go_package for each as below:
In A.proto option go_package = "github.com/myrepo/example-grpc-go/pkg/api/message/A/v1;v1";
In B.proto option go_package = "github.com/myrepo/example-grpc-go/pkg/api/message/B/v1;v1";
In common.proto option go_package = "github.com/myrepo/example-grpc-go/pkg/api/message/v1;v1";
Build command works fine and generates everything properly, but there is a problem with generated validator files. There's no import for that common file in the generated validator file and I because of that I cannot build the project.
generated validator file imports:
import (
"bytes"
"errors"
"fmt"
"net"
"net/mail"
"net/url"
"regexp"
"strings"
"time"
"unicode/utf8"
"github.com/golang/protobuf/ptypes"
)
what I expected to be:
import (
"bytes"
"errors"
"fmt"
"net"
"net/mail"
"net/url"
"regexp"
"strings"
"time"
"unicode/utf8"
"github.com/golang/protobuf/ptypes"
v1 "github.com/myrepo/example-grpc-go/pkg/api/message/v1"
)
Hey, thanks for the report! Would be helpful to have a (reduced) example of these protos. Otherwise, it's hard to distinguish what's happening here.
@rodaine I wrote this example in this morning: pgv-example
If you take a look at this line, you can see that FilterOperation_name
belongs to common/v1
package and this package didn't import there.
let me know if you need any more details.
thx
Hey group! I came across this exact thing about five minutes ago. Whilst the validation code generates just fine, the generated import() list in my *.validate.go file is missing code from a common proto type I use throughout my other protos.
// Expected `package proto_tf_x
import ( "bytes" "errors" "fmt" "net" "net/mail" "net/url" "regexp" "strings" "time" "unicode/utf8"
"github.com/golang/protobuf/ptypes"
"github.com/davedotdev/proj/proto_common" // I added this manually...
)`
// Actual `package proto_tf_x
import ( "bytes" "errors" "fmt" "net" "net/mail" "net/url" "regexp" "strings" "time" "unicode/utf8"
"github.com/golang/protobuf/ptypes"
)`
The generated code that I require validation on imports the davedotdev/proj/proto_common package.
Hope this helps!