From 89db5fe37801fefa499ace35233eed98de3f1604 Mon Sep 17 00:00:00 2001 From: Carlos Miguel Garcia <89794450+cmgsj@users.noreply.github.com> Date: Sat, 1 Feb 2025 05:18:45 -0500 Subject: [PATCH] Add support for protovalidate breaking changes (#29) Add support for protovalidate and protovalidate-go breaking changes. --------- Signed-off-by: cmgsj --- go.mod | 19 +++++---- go.sum | 42 ++++++++++--------- .../example/calculator/v1/calculator.pb.go | 28 ++++++------- internal/gen/example/user/v1/user.pb.go | 39 ++++++++--------- validate.go | 10 ++--- validate_test.go | 8 ++-- 6 files changed, 72 insertions(+), 74 deletions(-) diff --git a/go.mod b/go.mod index 86dff8e..dc7817d 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,25 @@ module connectrpc.com/validate -go 1.21.0 +go 1.21.1 require ( - buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.1-20240920164238-5a7b106cbb87.1 + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.4-20250130201111-63bb56e20495.1 connectrpc.com/connect v1.17.0 - github.com/bufbuild/protovalidate-go v0.7.2 - github.com/stretchr/testify v1.9.0 - google.golang.org/protobuf v1.35.1 + github.com/bufbuild/protovalidate-go v0.9.1 + github.com/stretchr/testify v1.10.0 + google.golang.org/protobuf v1.36.4 ) require ( + cel.dev/expr v0.19.1 // indirect github.com/antlr4-go/antlr/v4 v4.13.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/google/cel-go v0.21.0 // indirect + github.com/google/cel-go v0.23.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect + golang.org/x/text v0.21.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c56e4a3..a00ee1d 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,20 @@ -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.1-20240920164238-5a7b106cbb87.1 h1:9wP6ZZYWnF2Z0TxmII7m3XNykxnP4/w8oXeth6ekcRI= -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.1-20240920164238-5a7b106cbb87.1/go.mod h1:Duw/9JoXkXIydyASnLYIiufkzySThoqavOsF+IihqvM= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.4-20250130201111-63bb56e20495.1 h1:4erM3WLgEG/HIBrpBDmRbs1puhd7p0z7kNXDuhHthwM= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.4-20250130201111-63bb56e20495.1/go.mod h1:novQBstnxcGpfKf8qGRATqn1anQKwMJIbH5Q581jibU= +cel.dev/expr v0.19.1 h1:NciYrtDRIR0lNCnH1LFJegdjspNx9fI59O7TWcua/W4= +cel.dev/expr v0.19.1/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw= connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk= connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8= github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= -github.com/bufbuild/protovalidate-go v0.7.2 h1:UuvKyZHl5p7u3ztEjtRtqtDxOjRKX5VUOgKFq6p6ETk= -github.com/bufbuild/protovalidate-go v0.7.2/go.mod h1:PHV5pFuWlRzdDW02/cmVyNzdiQ+RNNwo7idGxdzS7o4= +github.com/bufbuild/protovalidate-go v0.9.1 h1:cdrIA33994yCcJyEIZRL36ZGTe9UDM/WHs5MBHEimiE= +github.com/bufbuild/protovalidate-go v0.9.1/go.mod h1:5jptBxfvlY51RhX32zR6875JfPBRXUsQjyZjm/NqkLQ= 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/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM= -github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4= -github.com/google/cel-go v0.21.0 h1:cl6uW/gxN+Hy50tNYvI691+sXxioCnstFzLp2WO4GCI= -github.com/google/cel-go v0.21.0/go.mod h1:rHUlWCcBKgyEk+eV03RPdZUekPp6YcJwV0FxuUksYxc= +github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8= +github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU= +github.com/google/cel-go v0.23.0 h1:knsnzeUOcREUFo0ZFJqZI8Rk6uEVyobAlir7GEbf5v0= +github.com/google/cel-go v0.23.0/go.mod h1:52Pb6QsDbC5kvgxvZhiL9QX1oZEkcUF/ZqaPx1J5Wwo= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -29,20 +31,20 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw= golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda h1:b6F6WIV4xHHD0FA4oIyzU6mHWg2WI2X1RBehwa5QN38= -google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda/go.mod h1:AHcE/gZH76Bk/ROZhQphlRoWo5xKDEtz3eVEO1LfA8c= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw= +google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 h1:2035KHhUv+EpyB+hWgJnaWKJOdX1E95w2S8Rr4uWKTs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM= +google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/gen/example/calculator/v1/calculator.pb.go b/internal/gen/example/calculator/v1/calculator.pb.go index 9658047..3759ae6 100644 --- a/internal/gen/example/calculator/v1/calculator.pb.go +++ b/internal/gen/example/calculator/v1/calculator.pb.go @@ -14,7 +14,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 +// protoc-gen-go v1.36.4 // protoc (unknown) // source: example/calculator/v1/calculator.proto @@ -26,6 +26,7 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + unsafe "unsafe" ) const ( @@ -36,11 +37,10 @@ const ( ) type CumSumRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` unknownFields protoimpl.UnknownFields - - Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` + sizeCache protoimpl.SizeCache } func (x *CumSumRequest) Reset() { @@ -81,11 +81,10 @@ func (x *CumSumRequest) GetNumber() int64 { } type CumSumResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Sum int64 `protobuf:"varint,1,opt,name=sum,proto3" json:"sum,omitempty"` unknownFields protoimpl.UnknownFields - - Sum int64 `protobuf:"varint,1,opt,name=sum,proto3" json:"sum,omitempty"` + sizeCache protoimpl.SizeCache } func (x *CumSumResponse) Reset() { @@ -127,7 +126,7 @@ func (x *CumSumResponse) GetSum() int64 { var File_example_calculator_v1_calculator_proto protoreflect.FileDescriptor -var file_example_calculator_v1_calculator_proto_rawDesc = []byte{ +var file_example_calculator_v1_calculator_proto_rawDesc = string([]byte{ 0x0a, 0x26, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x15, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, @@ -162,16 +161,16 @@ var file_example_calculator_v1_calculator_proto_rawDesc = []byte{ 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3a, 0x3a, 0x43, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} +}) var ( file_example_calculator_v1_calculator_proto_rawDescOnce sync.Once - file_example_calculator_v1_calculator_proto_rawDescData = file_example_calculator_v1_calculator_proto_rawDesc + file_example_calculator_v1_calculator_proto_rawDescData []byte ) func file_example_calculator_v1_calculator_proto_rawDescGZIP() []byte { file_example_calculator_v1_calculator_proto_rawDescOnce.Do(func() { - file_example_calculator_v1_calculator_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_calculator_v1_calculator_proto_rawDescData) + file_example_calculator_v1_calculator_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_example_calculator_v1_calculator_proto_rawDesc), len(file_example_calculator_v1_calculator_proto_rawDesc))) }) return file_example_calculator_v1_calculator_proto_rawDescData } @@ -200,7 +199,7 @@ func file_example_calculator_v1_calculator_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_example_calculator_v1_calculator_proto_rawDesc, + RawDescriptor: unsafe.Slice(unsafe.StringData(file_example_calculator_v1_calculator_proto_rawDesc), len(file_example_calculator_v1_calculator_proto_rawDesc)), NumEnums: 0, NumMessages: 2, NumExtensions: 0, @@ -211,7 +210,6 @@ func file_example_calculator_v1_calculator_proto_init() { MessageInfos: file_example_calculator_v1_calculator_proto_msgTypes, }.Build() File_example_calculator_v1_calculator_proto = out.File - file_example_calculator_v1_calculator_proto_rawDesc = nil file_example_calculator_v1_calculator_proto_goTypes = nil file_example_calculator_v1_calculator_proto_depIdxs = nil } diff --git a/internal/gen/example/user/v1/user.pb.go b/internal/gen/example/user/v1/user.pb.go index 10bd584..df5cd0d 100644 --- a/internal/gen/example/user/v1/user.pb.go +++ b/internal/gen/example/user/v1/user.pb.go @@ -14,7 +14,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 +// protoc-gen-go v1.36.4 // protoc (unknown) // source: example/user/v1/user.proto @@ -27,6 +27,7 @@ import ( timestamppb "google.golang.org/protobuf/types/known/timestamppb" reflect "reflect" sync "sync" + unsafe "unsafe" ) const ( @@ -37,13 +38,12 @@ const ( ) type User struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` + BirthDate *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=birth_date,json=birthDate,proto3" json:"birth_date,omitempty"` + SignupDate *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=signup_date,json=signupDate,proto3" json:"signup_date,omitempty"` unknownFields protoimpl.UnknownFields - - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` - BirthDate *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=birth_date,json=birthDate,proto3" json:"birth_date,omitempty"` - SignupDate *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=signup_date,json=signupDate,proto3" json:"signup_date,omitempty"` + sizeCache protoimpl.SizeCache } func (x *User) Reset() { @@ -98,11 +98,10 @@ func (x *User) GetSignupDate() *timestamppb.Timestamp { } type CreateUserRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` unknownFields protoimpl.UnknownFields - - User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + sizeCache protoimpl.SizeCache } func (x *CreateUserRequest) Reset() { @@ -143,11 +142,10 @@ func (x *CreateUserRequest) GetUser() *User { } type CreateUserResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` unknownFields protoimpl.UnknownFields - - User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + sizeCache protoimpl.SizeCache } func (x *CreateUserResponse) Reset() { @@ -189,7 +187,7 @@ func (x *CreateUserResponse) GetUser() *User { var File_example_user_v1_user_proto protoreflect.FileDescriptor -var file_example_user_v1_user_proto_rawDesc = []byte{ +var file_example_user_v1_user_proto_rawDesc = string([]byte{ 0x0a, 0x1a, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, @@ -241,16 +239,16 @@ var file_example_user_v1_user_proto_rawDesc = []byte{ 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3a, 0x3a, 0x55, 0x73, 0x65, 0x72, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} +}) var ( file_example_user_v1_user_proto_rawDescOnce sync.Once - file_example_user_v1_user_proto_rawDescData = file_example_user_v1_user_proto_rawDesc + file_example_user_v1_user_proto_rawDescData []byte ) func file_example_user_v1_user_proto_rawDescGZIP() []byte { file_example_user_v1_user_proto_rawDescOnce.Do(func() { - file_example_user_v1_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_user_v1_user_proto_rawDescData) + file_example_user_v1_user_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_example_user_v1_user_proto_rawDesc), len(file_example_user_v1_user_proto_rawDesc))) }) return file_example_user_v1_user_proto_rawDescData } @@ -285,7 +283,7 @@ func file_example_user_v1_user_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_example_user_v1_user_proto_rawDesc, + RawDescriptor: unsafe.Slice(unsafe.StringData(file_example_user_v1_user_proto_rawDesc), len(file_example_user_v1_user_proto_rawDesc)), NumEnums: 0, NumMessages: 3, NumExtensions: 0, @@ -296,7 +294,6 @@ func file_example_user_v1_user_proto_init() { MessageInfos: file_example_user_v1_user_proto_msgTypes, }.Build() File_example_user_v1_user_proto = out.File - file_example_user_v1_user_proto_rawDesc = nil file_example_user_v1_user_proto_goTypes = nil file_example_user_v1_user_proto_depIdxs = nil } diff --git a/validate.go b/validate.go index a7a4ab7..65b5d5e 100644 --- a/validate.go +++ b/validate.go @@ -37,7 +37,7 @@ type Option interface { // WithValidator configures the [Interceptor] to use a customized // [protovalidate.Validator]. See [protovalidate.ValidatorOption] for the range // of available customizations. -func WithValidator(validator *protovalidate.Validator) Option { +func WithValidator(validator protovalidate.Validator) Option { return optionFunc(func(i *Interceptor) { i.validator = validator }) @@ -63,7 +63,7 @@ func WithValidator(validator *protovalidate.Validator) Option { // // [detailed representation of the error]: https://pkg.go.dev/buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate#Violations type Interceptor struct { - validator *protovalidate.Validator + validator protovalidate.Validator } // NewInterceptor builds an Interceptor. The default configuration is @@ -118,7 +118,7 @@ func (i *Interceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) co type streamingClientInterceptor struct { connect.StreamingClientConn - validator *protovalidate.Validator + validator protovalidate.Validator } func (s *streamingClientInterceptor) Send(msg any) error { @@ -131,7 +131,7 @@ func (s *streamingClientInterceptor) Send(msg any) error { type streamingHandlerInterceptor struct { connect.StreamingHandlerConn - validator *protovalidate.Validator + validator protovalidate.Validator } func (s *streamingHandlerInterceptor) Receive(msg any) error { @@ -145,7 +145,7 @@ type optionFunc func(*Interceptor) func (f optionFunc) apply(i *Interceptor) { f(i) } -func validate(validator *protovalidate.Validator, msg any) error { +func validate(validator protovalidate.Validator, msg any) error { protoMsg, ok := msg.(proto.Message) if !ok { return fmt.Errorf("expected proto.Message, got %T", msg) diff --git a/validate_test.go b/validate_test.go index 8cd84b5..7e5e6e3 100644 --- a/validate_test.go +++ b/validate_test.go @@ -102,7 +102,7 @@ func TestInterceptorUnary(t *testing.T) { violations, ok := detail.(*validatepb.Violations) require.True(t, ok) require.Len(t, violations.Violations, 1) - require.Equal(t, test.wantPath, violations.Violations[0].GetFieldPath()) + require.Equal(t, test.wantPath, protovalidate.FieldPathString(violations.Violations[0].GetField())) } } else { require.NoError(t, err) @@ -188,7 +188,7 @@ func TestInterceptorStreamingHandler(t *testing.T) { violations, ok := detail.(*validatepb.Violations) require.True(t, ok) require.Len(t, violations.Violations, 1) - require.Equal(t, test.wantPath, violations.Violations[0].GetFieldPath()) + require.Equal(t, test.wantPath, protovalidate.FieldPathString(violations.Violations[0].GetField())) } } else { require.NoError(t, err) @@ -275,7 +275,7 @@ func TestInterceptorStreamingClient(t *testing.T) { violations, ok := detail.(*validatepb.Violations) require.True(t, ok) require.Len(t, violations.Violations, 1) - require.Equal(t, test.wantPath, violations.Violations[0].GetFieldPath()) + require.Equal(t, test.wantPath, protovalidate.FieldPathString(violations.Violations[0].GetField())) } } else { require.NoError(t, err) @@ -293,7 +293,7 @@ func TestInterceptorStreamingClient(t *testing.T) { func TestWithValidator(t *testing.T) { t.Parallel() - validator, err := protovalidate.New(protovalidate.WithDisableLazy(true)) + validator, err := protovalidate.New(protovalidate.WithDisableLazy()) require.NoError(t, err) interceptor, err := validate.NewInterceptor(validate.WithValidator(validator)) require.NoError(t, err)