diff --git a/go.sum b/go.sum index 70c16bc..21d8b57 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ 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:f9Of0TRMdB+A2mZVJFUadESOOx0RfvBXR2FBFz/9hyI= +github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask h1:vIdGpbSKd0SJJoC+BEZc/17W+N3CKh6qjfpXKbyCw7g= 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= diff --git a/main_test.go b/main_test.go index 43c05d0..173481d 100644 --- a/main_test.go +++ b/main_test.go @@ -143,6 +143,8 @@ func TestFieldMaskPaths(t *testing.T) { "a.a.d", "a.a.h", "a.a.h.nested_field", + "a.a.i", + "a.a.i.nested_field_2", "a.a.testNestedNestedOneOf", "a.a.testNestedNestedOneOf.e", "a.a.testNestedNestedOneOf.f", @@ -160,6 +162,8 @@ func TestFieldMaskPaths(t *testing.T) { "b.a.d", "b.a.h", "b.a.h.nested_field", + "b.a.i", + "b.a.i.nested_field_2", "b.a.testNestedNestedOneOf", "b.a.testNestedNestedOneOf.e", "b.a.testNestedNestedOneOf.f", @@ -177,6 +181,8 @@ func TestFieldMaskPaths(t *testing.T) { "c.a.d", "c.a.h", "c.a.h.nested_field", + "c.a.i", + "c.a.i.nested_field_2", "c.a.testNestedNestedOneOf", "c.a.testNestedNestedOneOf.e", "c.a.testNestedNestedOneOf.f", @@ -212,6 +218,8 @@ func TestFieldMaskPaths(t *testing.T) { "a.d", "a.h", "a.h.nested_field", + "a.i", + "a.i.nested_field_2", "a.testNestedNestedOneOf", "a.testNestedNestedOneOf.e", "a.testNestedNestedOneOf.f", @@ -238,6 +246,8 @@ func TestFieldMaskPaths(t *testing.T) { "d", "h", "h.nested_field", + "i", + "i.nested_field_2", "testNestedNestedOneOf", "testNestedNestedOneOf.e", "testNestedNestedOneOf.f", @@ -249,6 +259,7 @@ func TestFieldMaskPaths(t *testing.T) { "c", "d", "h", + "i", "testNestedNestedOneOf", }) } @@ -496,13 +507,16 @@ func TestValidateFields(t *testing.T) { A: &testdata.Test_TestNested{ A: &testdata.Test_TestNested_TestNestedNested{ A: 42, + Test_TestNested_TestNestedNested_TestNestedNestedEmbed2: testdata.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2{ + NestedField_2: 2, + }, }, C: func(v time.Duration) *time.Duration { return &v }(43 * time.Second), }, }, }, { - Name: "nil paths/invalid", + Name: "nil paths/invalid a.a.a", Message: &testdata.Test{ A: &testdata.Test_TestNested{ A: &testdata.Test_TestNested_TestNestedNested{ @@ -512,6 +526,29 @@ func TestValidateFields(t *testing.T) { }, ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) }, }, + { + Name: "a.a.i/valid a.a.i.nested_field_2", + Message: &testdata.Test{ + A: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{ + Test_TestNested_TestNestedNested_TestNestedNestedEmbed2: testdata.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2{ + NestedField_2: 2, + }, + }, + }, + }, + Paths: []string{"a.a.i"}, + }, + { + Name: "a.a.i/invalid a.a.i.nested_field_2", + Message: &testdata.Test{ + A: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{}, + }, + }, + Paths: []string{"a.a.i"}, + ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) }, + }, { Name: "non-existent sub-field", Message: &testdata.Test{}, diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index 94b4ee0..c7c2f06 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -341,6 +341,7 @@ type Test_TestNested_TestNestedNested struct { // *Test_TestNested_TestNestedNested_G TestNestedNestedOneOf isTest_TestNested_TestNestedNested_TestNestedNestedOneOf `protobuf_oneof:"testNestedNestedOneOf"` *Test_TestNested_TestNestedNested_TestNestedNestedEmbed `protobuf:"bytes,8,opt,name=h,proto3,embedded=h" json:"h,omitempty"` + Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 `protobuf:"bytes,9,opt,name=i,proto3,embedded=i" json:"i"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -577,6 +578,48 @@ func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) GetNestedField( return 0 } +type Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 struct { + NestedField_2 int32 `protobuf:"varint,1,opt,name=nested_field_2,json=nestedField2,proto3" json:"nested_field_2,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) Reset() { + *m = Test_TestNested_TestNestedNested_TestNestedNestedEmbed2{} +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) String() string { + return proto.CompactTextString(m) +} +func (*Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) ProtoMessage() {} +func (*Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) Descriptor() ([]byte, []int) { + return fileDescriptor_40c4782d007dfce9, []int{1, 0, 0, 2} +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed2.Unmarshal(m, b) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed2.Marshal(b, m, deterministic) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) XXX_Merge(src proto.Message) { + xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed2.Merge(m, src) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) XXX_Size() int { + return xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed2.Size(m) +} +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) XXX_DiscardUnknown() { + xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed2.DiscardUnknown(m) +} + +var xxx_messageInfo_Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 proto.InternalMessageInfo + +func (m *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) GetNestedField_2() int32 { + if m != nil { + return m.NestedField_2 + } + return 0 +} + func init() { proto.RegisterType((*Empty)(nil), "testdata.Empty") proto.RegisterType((*Test)(nil), "testdata.Test") @@ -584,53 +627,57 @@ func init() { 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") + proto.RegisterType((*Test_TestNested_TestNestedNested_TestNestedNestedEmbed2)(nil), "testdata.Test.TestNested.TestNestedNested.TestNestedNestedEmbed2") } func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 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, - 0x83, 0x43, 0x55, 0x10, 0xe2, 0x62, 0xcd, 0xec, 0xcc, 0xec, 0x78, 0x7e, 0xf3, 0x5f, 0xb8, 0xcc, - 0x48, 0xc4, 0x2c, 0xcc, 0xb0, 0x1e, 0x84, 0x3e, 0xf3, 0xd1, 0x62, 0xea, 0xab, 0x6d, 0xea, 0xb0, - 0x61, 0xdc, 0xd7, 0x07, 0xbe, 0xdb, 0xa1, 0x3e, 0xf5, 0x3b, 0x22, 0xa1, 0x1f, 0xdb, 0xc2, 0x13, - 0x8e, 0xb0, 0x64, 0xa1, 0x7a, 0x6f, 0x2a, 0x7d, 0x34, 0xb6, 0x99, 0x4c, 0x1f, 0xb4, 0x29, 0xf1, - 0xda, 0x47, 0x78, 0xe4, 0x58, 0x98, 0x91, 0xce, 0x8c, 0x31, 0x29, 0xbe, 0x4c, 0x7d, 0x9f, 0x8e, - 0x48, 0xd6, 0xc2, 0x8a, 0x43, 0xcc, 0x1c, 0xdf, 0x9b, 0xc4, 0xb5, 0x7c, 0x9c, 0x39, 0x2e, 0x89, - 0x18, 0x76, 0x83, 0xd3, 0x2e, 0x78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 0xe7, 0x59, 0x0d, 0x3e, 0xdb, 0xf5, 0xd8, 0xed, 0x0d, 0xa1, 0x41, 0x9e, - 0x4d, 0x51, 0x2f, 0x53, 0xf7, 0xa3, 0xbf, 0xf8, 0xbf, 0xfc, 0xc1, 0x8e, 0xdb, 0xe7, 0xef, 0xf2, - 0x6b, 0xc2, 0x35, 0x31, 0x54, 0x37, 0x60, 0x59, 0x4e, 0x80, 0xea, 0xb0, 0x70, 0x48, 0xc6, 0x12, - 0x9c, 0xc9, 0x4d, 0x74, 0x1e, 0x96, 0x8e, 0x78, 0x7f, 0x41, 0x6c, 0xc9, 0x94, 0xce, 0xd6, 0xfc, - 0x26, 0x50, 0xb7, 0xe0, 0xea, 0x6f, 0xef, 0x45, 0x57, 0x60, 0xcd, 0x13, 0xee, 0x6b, 0xb1, 0xc7, - 0xc9, 0x6d, 0x55, 0x79, 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, + // 721 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xcb, 0x6e, 0xd3, 0x4c, + 0x14, 0xc7, 0x3b, 0x89, 0x93, 0x26, 0x93, 0x34, 0x8d, 0xe6, 0xfb, 0x0a, 0xae, 0x05, 0x38, 0x94, + 0x05, 0x51, 0x44, 0x1c, 0x08, 0x15, 0x94, 0x82, 0xb8, 0x98, 0x16, 0xd1, 0x4d, 0x2b, 0xb9, 0x01, + 0x04, 0x2c, 0xaa, 0x49, 0x3c, 0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, 0xb5, 0xa3, 0xac, 0xc2, 0xbc, 0x80, 0x83, 0xaa, 0x30, + 0xbb, 0x4f, 0x46, 0x62, 0x27, 0x06, 0x33, 0xd1, 0xff, 0x30, 0x77, 0xc0, 0x46, 0xe3, 0xcb, 0x58, + 0x30, 0x84, 0xb3, 0x9e, 0x59, 0x03, 0xca, 0x3a, 0x5c, 0x3a, 0xb6, 0x39, 0xba, 0x0c, 0xcb, 0x1e, + 0x77, 0xf7, 0xb8, 0x44, 0x26, 0xdd, 0x4a, 0xe2, 0xec, 0x09, 0x3b, 0x52, 0xb6, 0xe0, 0xb9, 0xe3, + 0x1f, 0x86, 0x5a, 0xb0, 0x92, 0x2e, 0xde, 0x6b, 0x4f, 0x04, 0x52, 0x64, 0x02, 0x91, 0x94, 0x4c, + 0x21, 0x63, 0x94, 0x53, 0x9d, 0xda, 0xfa, 0x79, 0xb8, 0x44, 0xa7, 0x5a, 0xed, 0x78, 0x64, 0xc7, + 0xd2, 0x4b, 0xb0, 0xc8, 0x02, 0xfc, 0x5f, 0x4a, 0xbf, 0xff, 0xea, 0xde, 0x59, 0x94, 0xdd, 0xcd, + 0xf3, 0xf0, 0xcd, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcb, 0x88, 0xb1, 0x92, 0xa8, 0x06, 0x00, + 0x00, } diff --git a/testdata/testdata.pb.paths.fm.go b/testdata/testdata.pb.paths.fm.go index 23cc37c..7119820 100644 --- a/testdata/testdata.pb.paths.fm.go +++ b/testdata/testdata.pb.paths.fm.go @@ -13,6 +13,8 @@ var TestFieldPathsNested = []string{ "a.a.d", "a.a.h", "a.a.h.nested_field", + "a.a.i", + "a.a.i.nested_field_2", "a.a.testNestedNestedOneOf", "a.a.testNestedNestedOneOf.e", "a.a.testNestedNestedOneOf.f", @@ -30,6 +32,8 @@ var TestFieldPathsNested = []string{ "b.a.d", "b.a.h", "b.a.h.nested_field", + "b.a.i", + "b.a.i.nested_field_2", "b.a.testNestedNestedOneOf", "b.a.testNestedNestedOneOf.e", "b.a.testNestedNestedOneOf.f", @@ -47,6 +51,8 @@ var TestFieldPathsNested = []string{ "c.a.d", "c.a.h", "c.a.h.nested_field", + "c.a.i", + "c.a.i.nested_field_2", "c.a.testNestedNestedOneOf", "c.a.testNestedNestedOneOf.e", "c.a.testNestedNestedOneOf.f", @@ -82,6 +88,8 @@ var Test_TestNestedFieldPathsNested = []string{ "a.d", "a.h", "a.h.nested_field", + "a.i", + "a.i.nested_field_2", "a.testNestedNestedOneOf", "a.testNestedNestedOneOf.e", "a.testNestedNestedOneOf.f", @@ -108,6 +116,8 @@ var Test_TestNested_TestNestedNestedFieldPathsNested = []string{ "d", "h", "h.nested_field", + "i", + "i.nested_field_2", "testNestedNestedOneOf", "testNestedNestedOneOf.e", "testNestedNestedOneOf.f", @@ -120,6 +130,7 @@ var Test_TestNested_TestNestedNestedFieldPathsTopLevel = []string{ "c", "d", "h", + "i", "testNestedNestedOneOf", } var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested = []string{ @@ -129,3 +140,10 @@ var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsNested = []s var Test_TestNested_TestNestedNested_TestNestedNestedEmbedFieldPathsTopLevel = []string{ "nested_field", } +var Test_TestNested_TestNestedNested_TestNestedNestedEmbed2FieldPathsNested = []string{ + "nested_field_2", +} + +var Test_TestNested_TestNestedNested_TestNestedNestedEmbed2FieldPathsTopLevel = []string{ + "nested_field_2", +} diff --git a/testdata/testdata.pb.setters.fm.go b/testdata/testdata.pb.setters.fm.go index f7fa020..6a9e9a0 100644 --- a/testdata/testdata.pb.setters.fm.go +++ b/testdata/testdata.pb.setters.fm.go @@ -328,6 +328,24 @@ func (dst *Test_TestNested_TestNestedNested) SetFields(src *Test_TestNested_Test dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed = nil } } + case "i": + if len(subs) > 0 { + newDst := &dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 + var newSrc *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 + if src != nil { + newSrc = &src.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 + } + if err := newDst.SetFields(newSrc, subs...); err != nil { + return err + } + } else { + if src != nil { + dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 = src.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 + } else { + var zero Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 + dst.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 = zero + } + } case "testNestedNestedOneOf": if len(subs) == 0 && src == nil { @@ -426,3 +444,24 @@ func (dst *Test_TestNested_TestNestedNested_TestNestedNestedEmbed) SetFields(src } return nil } + +func (dst *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2) SetFields(src *Test_TestNested_TestNestedNested_TestNestedNestedEmbed2, paths ...string) error { + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + switch name { + case "nested_field_2": + if len(subs) > 0 { + return fmt.Errorf("'nested_field_2' has no subfields, but %s were specified", subs) + } + if src != nil { + dst.NestedField_2 = src.NestedField_2 + } else { + var zero int32 + dst.NestedField_2 = zero + } + + default: + return fmt.Errorf("invalid field: '%s'", name) + } + } + return nil +} diff --git a/testdata/testdata.pb.validate.go b/testdata/testdata.pb.validate.go index 6744e2e..8bb69a6 100644 --- a/testdata/testdata.pb.validate.go +++ b/testdata/testdata.pb.validate.go @@ -136,7 +136,7 @@ func (m *Test) ValidateFields(paths ...string) error { case "c": - if v, ok := interface{}(m.GetC()).(interface{ ValidateFields(...string) error }); ok { + if v, ok := interface{}(&m.C).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ field: "c", @@ -172,7 +172,7 @@ func (m *Test) ValidateFields(paths ...string) error { case "i": - if v, ok := interface{}(m.GetI()).(interface{ ValidateFields(...string) error }); ok { + if v, ok := interface{}(&m.I).(interface{ ValidateFields(...string) error }); ok { if err := v.ValidateFields(subs...); err != nil { return TestValidationError{ field: "i", @@ -430,6 +430,18 @@ func (m *Test_TestNested_TestNestedNested) ValidateFields(paths ...string) error } } + case "i": + + if v, ok := interface{}(&m.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return Test_TestNested_TestNestedNestedValidationError{ + field: "i", + reason: "embedded message failed validation", + cause: err, + } + } + } + case "testNestedNestedOneOf": if len(subs) == 0 { subs = []string{ @@ -627,3 +639,104 @@ var _ interface { Cause() error ErrorName() string } = Test_TestNested_TestNestedNested_TestNestedNestedEmbedValidationError{} + +// ValidateFields checks the field values on +// Test_TestNested_TestNestedNested_TestNestedNestedEmbed2 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_TestNestedNestedEmbed2) ValidateFields(paths ...string) error { + if m == nil { + return nil + } + + if len(paths) == 0 { + paths = Test_TestNested_TestNestedNested_TestNestedNestedEmbed2FieldPathsNested + } + + for name, subs := range _processPaths(append(paths[:0:0], paths...)) { + _ = subs + switch name { + case "nested_field_2": + + if m.GetNestedField_2() != 2 { + return Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError{ + field: "nested_field_2", + reason: "value must equal 2", + } + } + + default: + return Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError{ + field: name, + reason: "invalid field path", + } + } + } + return nil +} + +// Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError is +// the validation error returned by +// Test_TestNested_TestNestedNested_TestNestedNestedEmbed2.ValidateFields if +// the designated constraints aren't met. +type Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError) Field() string { + return e.field +} + +// Reason function returns reason value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError) Reason() string { + return e.reason +} + +// Cause function returns cause value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError) Cause() error { + return e.cause +} + +// Key function returns key value. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError) Key() bool { + return e.key +} + +// ErrorName returns error name. +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError) ErrorName() string { + return "Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError" +} + +// Error satisfies the builtin error interface +func (e Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError) 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_TestNestedNestedEmbed2.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = Test_TestNested_TestNestedNested_TestNestedNestedEmbed2ValidationError{} diff --git a/testdata/testdata.proto b/testdata/testdata.proto index 8b20228..ca63f83 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -42,6 +42,11 @@ message Test { int32 nested_field = 1; } TestNestedNestedEmbed h = 8 [(gogoproto.embed) = true]; + + message TestNestedNestedEmbed2 { + int32 nested_field_2 = 1 [(validate.rules).int32.const = 2]; + } + TestNestedNestedEmbed2 i = 9 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; } TestNestedNested a = 1; bytes b = 2;