diff --git a/proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto3.proto b/proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto3.proto index 81b68475..9d08abe5 100644 --- a/proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto3.proto +++ b/proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto3.proto @@ -68,3 +68,23 @@ message IgnoreEmptyProto3Map { (buf.validate.field).map.min_pairs = 3 ]; } + +message IgnoreEmptyRepeatedItems { + repeated int32 val = 1 [(buf.validate.field).repeated.items = { + ignore_empty: true, + int32: {gt: 0}, + }]; +} + +message IgnoreEmptyMapPairs { + map val = 1 [ + (buf.validate.field).map.keys = { + ignore_empty: true, + string: {min_len: 3}, + }, + (buf.validate.field).map.values = { + ignore_empty: true, + int32: {gt: 0}, + } + ]; +} diff --git a/proto/protovalidate-testing/buf/validate/conformance/cases/oneofs.proto b/proto/protovalidate-testing/buf/validate/conformance/cases/oneofs.proto index 37a0d875..2a524c51 100644 --- a/proto/protovalidate-testing/buf/validate/conformance/cases/oneofs.proto +++ b/proto/protovalidate-testing/buf/validate/conformance/cases/oneofs.proto @@ -56,29 +56,3 @@ message OneofRequiredWithRequiredField { string b = 2; } } - -message OneofIgnoreEmpty { - oneof o { - string x = 1 [ - (buf.validate.field).string = { - min_len: 3, - max_len: 5 - }, - (buf.validate.field).ignore_empty = true - ]; - bytes y = 2 [ - (buf.validate.field).bytes = { - min_len: 3, - max_len: 5 - }, - (buf.validate.field).ignore_empty = true - ]; - int32 z = 3 [ - (buf.validate.field).int32 = { - gte: 128, - lte: 256, - }, - (buf.validate.field).ignore_empty = true - ]; - } -} diff --git a/tools/internal/gen/buf/validate/conformance/cases/ignore_empty_proto3.pb.go b/tools/internal/gen/buf/validate/conformance/cases/ignore_empty_proto3.pb.go index ca116e82..2a48b013 100644 --- a/tools/internal/gen/buf/validate/conformance/cases/ignore_empty_proto3.pb.go +++ b/tools/internal/gen/buf/validate/conformance/cases/ignore_empty_proto3.pb.go @@ -337,6 +337,100 @@ func (x *IgnoreEmptyProto3Map) GetVal() map[int32]int32 { return nil } +type IgnoreEmptyRepeatedItems struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Val []int32 `protobuf:"varint,1,rep,packed,name=val,proto3" json:"val,omitempty"` +} + +func (x *IgnoreEmptyRepeatedItems) Reset() { + *x = IgnoreEmptyRepeatedItems{} + if protoimpl.UnsafeEnabled { + mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IgnoreEmptyRepeatedItems) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IgnoreEmptyRepeatedItems) ProtoMessage() {} + +func (x *IgnoreEmptyRepeatedItems) ProtoReflect() protoreflect.Message { + mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IgnoreEmptyRepeatedItems.ProtoReflect.Descriptor instead. +func (*IgnoreEmptyRepeatedItems) Descriptor() ([]byte, []int) { + return file_buf_validate_conformance_cases_ignore_empty_proto3_proto_rawDescGZIP(), []int{6} +} + +func (x *IgnoreEmptyRepeatedItems) GetVal() []int32 { + if x != nil { + return x.Val + } + return nil +} + +type IgnoreEmptyMapPairs struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Val map[string]int32 `protobuf:"bytes,1,rep,name=val,proto3" json:"val,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` +} + +func (x *IgnoreEmptyMapPairs) Reset() { + *x = IgnoreEmptyMapPairs{} + if protoimpl.UnsafeEnabled { + mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IgnoreEmptyMapPairs) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IgnoreEmptyMapPairs) ProtoMessage() {} + +func (x *IgnoreEmptyMapPairs) ProtoReflect() protoreflect.Message { + mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IgnoreEmptyMapPairs.ProtoReflect.Descriptor instead. +func (*IgnoreEmptyMapPairs) Descriptor() ([]byte, []int) { + return file_buf_validate_conformance_cases_ignore_empty_proto3_proto_rawDescGZIP(), []int{7} +} + +func (x *IgnoreEmptyMapPairs) GetVal() map[string]int32 { + if x != nil { + return x.Val + } + return nil +} + type IgnoreEmptyProto3Message_Msg struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -348,7 +442,7 @@ type IgnoreEmptyProto3Message_Msg struct { func (x *IgnoreEmptyProto3Message_Msg) Reset() { *x = IgnoreEmptyProto3Message_Msg{} if protoimpl.UnsafeEnabled { - mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[6] + mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -361,7 +455,7 @@ func (x *IgnoreEmptyProto3Message_Msg) String() string { func (*IgnoreEmptyProto3Message_Msg) ProtoMessage() {} func (x *IgnoreEmptyProto3Message_Msg) ProtoReflect() protoreflect.Message { - mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[6] + mi := &file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -434,27 +528,42 @@ var file_buf_validate_conformance_cases_ignore_empty_proto3_proto_rawDesc = []by 0x08, 0x03, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x1a, 0x36, 0x0a, 0x08, 0x56, 0x61, 0x6c, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, - 0xad, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, - 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x42, 0x16, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, - 0x5a, 0x53, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, - 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x65, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, - 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x65, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, - 0x63, 0x61, 0x73, 0x65, 0x73, 0xa2, 0x02, 0x04, 0x42, 0x56, 0x43, 0x43, 0xaa, 0x02, 0x1e, 0x42, - 0x75, 0x66, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, - 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x43, 0x61, 0x73, 0x65, 0x73, 0xca, 0x02, 0x1e, - 0x42, 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, - 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0xe2, 0x02, - 0x2a, 0x42, 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, - 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x42, 0x75, - 0x66, 0x3a, 0x3a, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, - 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x3a, 0x3a, 0x43, 0x61, 0x73, 0x65, 0x73, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, + 0x3d, 0x0a, 0x18, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, + 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x21, 0x0a, 0x03, 0x76, + 0x61, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x05, 0x42, 0x0f, 0xba, 0x48, 0x0c, 0x92, 0x01, 0x09, + 0x22, 0x07, 0xd0, 0x01, 0x01, 0x1a, 0x02, 0x20, 0x00, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0xb7, + 0x01, 0x0a, 0x13, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x4d, 0x61, + 0x70, 0x50, 0x61, 0x69, 0x72, 0x73, 0x12, 0x68, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x3c, 0x2e, 0x62, 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, + 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, + 0x61, 0x73, 0x65, 0x73, 0x2e, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x4d, 0x61, 0x70, 0x50, 0x61, 0x69, 0x72, 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x42, 0x18, 0xba, 0x48, 0x15, 0x9a, 0x01, 0x12, 0x22, 0x07, 0xd0, 0x01, 0x01, 0x72, 0x02, + 0x10, 0x03, 0x2a, 0x07, 0xd0, 0x01, 0x01, 0x1a, 0x02, 0x20, 0x00, 0x52, 0x03, 0x76, 0x61, 0x6c, + 0x1a, 0x36, 0x0a, 0x08, 0x56, 0x61, 0x6c, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0xad, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, + 0x2e, 0x62, 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, + 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x42, + 0x16, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x33, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x53, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x74, 0x6f, 0x6f, + 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, + 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x63, 0x6f, 0x6e, + 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, 0x73, 0x65, 0x73, 0xa2, 0x02, + 0x04, 0x42, 0x56, 0x43, 0x43, 0xaa, 0x02, 0x1e, 0x42, 0x75, 0x66, 0x2e, 0x56, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, + 0x2e, 0x43, 0x61, 0x73, 0x65, 0x73, 0xca, 0x02, 0x1e, 0x42, 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, + 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0xe2, 0x02, 0x2a, 0x42, 0x75, 0x66, 0x5c, 0x56, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, + 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x42, 0x75, 0x66, 0x3a, 0x3a, 0x56, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, + 0x65, 0x3a, 0x3a, 0x43, 0x61, 0x73, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -469,7 +578,7 @@ func file_buf_validate_conformance_cases_ignore_empty_proto3_proto_rawDescGZIP() return file_buf_validate_conformance_cases_ignore_empty_proto3_proto_rawDescData } -var file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_buf_validate_conformance_cases_ignore_empty_proto3_proto_goTypes = []interface{}{ (*IgnoreEmptyProto3Scalar)(nil), // 0: buf.validate.conformance.cases.IgnoreEmptyProto3Scalar (*IgnoreEmptyProto3OptionalScalar)(nil), // 1: buf.validate.conformance.cases.IgnoreEmptyProto3OptionalScalar @@ -477,17 +586,21 @@ var file_buf_validate_conformance_cases_ignore_empty_proto3_proto_goTypes = []in (*IgnoreEmptyProto3Oneof)(nil), // 3: buf.validate.conformance.cases.IgnoreEmptyProto3Oneof (*IgnoreEmptyProto3Repeated)(nil), // 4: buf.validate.conformance.cases.IgnoreEmptyProto3Repeated (*IgnoreEmptyProto3Map)(nil), // 5: buf.validate.conformance.cases.IgnoreEmptyProto3Map - (*IgnoreEmptyProto3Message_Msg)(nil), // 6: buf.validate.conformance.cases.IgnoreEmptyProto3Message.Msg - nil, // 7: buf.validate.conformance.cases.IgnoreEmptyProto3Map.ValEntry + (*IgnoreEmptyRepeatedItems)(nil), // 6: buf.validate.conformance.cases.IgnoreEmptyRepeatedItems + (*IgnoreEmptyMapPairs)(nil), // 7: buf.validate.conformance.cases.IgnoreEmptyMapPairs + (*IgnoreEmptyProto3Message_Msg)(nil), // 8: buf.validate.conformance.cases.IgnoreEmptyProto3Message.Msg + nil, // 9: buf.validate.conformance.cases.IgnoreEmptyProto3Map.ValEntry + nil, // 10: buf.validate.conformance.cases.IgnoreEmptyMapPairs.ValEntry } var file_buf_validate_conformance_cases_ignore_empty_proto3_proto_depIdxs = []int32{ - 6, // 0: buf.validate.conformance.cases.IgnoreEmptyProto3Message.val:type_name -> buf.validate.conformance.cases.IgnoreEmptyProto3Message.Msg - 7, // 1: buf.validate.conformance.cases.IgnoreEmptyProto3Map.val:type_name -> buf.validate.conformance.cases.IgnoreEmptyProto3Map.ValEntry - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 8, // 0: buf.validate.conformance.cases.IgnoreEmptyProto3Message.val:type_name -> buf.validate.conformance.cases.IgnoreEmptyProto3Message.Msg + 9, // 1: buf.validate.conformance.cases.IgnoreEmptyProto3Map.val:type_name -> buf.validate.conformance.cases.IgnoreEmptyProto3Map.ValEntry + 10, // 2: buf.validate.conformance.cases.IgnoreEmptyMapPairs.val:type_name -> buf.validate.conformance.cases.IgnoreEmptyMapPairs.ValEntry + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_buf_validate_conformance_cases_ignore_empty_proto3_proto_init() } @@ -569,6 +682,30 @@ func file_buf_validate_conformance_cases_ignore_empty_proto3_proto_init() { } } file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IgnoreEmptyRepeatedItems); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IgnoreEmptyMapPairs); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_buf_validate_conformance_cases_ignore_empty_proto3_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*IgnoreEmptyProto3Message_Msg); i { case 0: return &v.state @@ -592,7 +729,7 @@ func file_buf_validate_conformance_cases_ignore_empty_proto3_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_buf_validate_conformance_cases_ignore_empty_proto3_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 11, NumExtensions: 0, NumServices: 0, }, diff --git a/tools/internal/gen/buf/validate/conformance/cases/oneofs.pb.go b/tools/internal/gen/buf/validate/conformance/cases/oneofs.pb.go index fec9f9dc..bd3d45b3 100644 --- a/tools/internal/gen/buf/validate/conformance/cases/oneofs.pb.go +++ b/tools/internal/gen/buf/validate/conformance/cases/oneofs.pb.go @@ -448,101 +448,6 @@ func (*OneofRequiredWithRequiredField_A) isOneofRequiredWithRequiredField_O() {} func (*OneofRequiredWithRequiredField_B) isOneofRequiredWithRequiredField_O() {} -type OneofIgnoreEmpty struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // Types that are assignable to O: - // - // *OneofIgnoreEmpty_X - // *OneofIgnoreEmpty_Y - // *OneofIgnoreEmpty_Z - O isOneofIgnoreEmpty_O `protobuf_oneof:"o"` -} - -func (x *OneofIgnoreEmpty) Reset() { - *x = OneofIgnoreEmpty{} - if protoimpl.UnsafeEnabled { - mi := &file_buf_validate_conformance_cases_oneofs_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *OneofIgnoreEmpty) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*OneofIgnoreEmpty) ProtoMessage() {} - -func (x *OneofIgnoreEmpty) ProtoReflect() protoreflect.Message { - mi := &file_buf_validate_conformance_cases_oneofs_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use OneofIgnoreEmpty.ProtoReflect.Descriptor instead. -func (*OneofIgnoreEmpty) Descriptor() ([]byte, []int) { - return file_buf_validate_conformance_cases_oneofs_proto_rawDescGZIP(), []int{5} -} - -func (m *OneofIgnoreEmpty) GetO() isOneofIgnoreEmpty_O { - if m != nil { - return m.O - } - return nil -} - -func (x *OneofIgnoreEmpty) GetX() string { - if x, ok := x.GetO().(*OneofIgnoreEmpty_X); ok { - return x.X - } - return "" -} - -func (x *OneofIgnoreEmpty) GetY() []byte { - if x, ok := x.GetO().(*OneofIgnoreEmpty_Y); ok { - return x.Y - } - return nil -} - -func (x *OneofIgnoreEmpty) GetZ() int32 { - if x, ok := x.GetO().(*OneofIgnoreEmpty_Z); ok { - return x.Z - } - return 0 -} - -type isOneofIgnoreEmpty_O interface { - isOneofIgnoreEmpty_O() -} - -type OneofIgnoreEmpty_X struct { - X string `protobuf:"bytes,1,opt,name=x,proto3,oneof"` -} - -type OneofIgnoreEmpty_Y struct { - Y []byte `protobuf:"bytes,2,opt,name=y,proto3,oneof"` -} - -type OneofIgnoreEmpty_Z struct { - Z int32 `protobuf:"varint,3,opt,name=z,proto3,oneof"` -} - -func (*OneofIgnoreEmpty_X) isOneofIgnoreEmpty_O() {} - -func (*OneofIgnoreEmpty_Y) isOneofIgnoreEmpty_O() {} - -func (*OneofIgnoreEmpty_Z) isOneofIgnoreEmpty_O() {} - var File_buf_validate_conformance_cases_oneofs_proto protoreflect.FileDescriptor var file_buf_validate_conformance_cases_oneofs_proto_rawDesc = []byte{ @@ -582,33 +487,25 @@ var file_buf_validate_conformance_cases_oneofs_proto_rawDesc = []byte{ 0x01, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xba, 0x48, 0x03, 0xc8, 0x01, 0x01, 0x48, 0x00, 0x52, 0x01, 0x61, 0x12, 0x0e, 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x01, 0x62, 0x42, 0x0a, 0x0a, 0x01, 0x6f, 0x12, 0x05, 0xba, 0x48, 0x02, 0x08, - 0x01, 0x22, 0x73, 0x0a, 0x10, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x1c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x0c, 0xba, 0x48, 0x09, 0xd0, 0x01, 0x01, 0x72, 0x04, 0x10, 0x03, 0x18, 0x05, 0x48, 0x00, - 0x52, 0x01, 0x78, 0x12, 0x1c, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x0c, - 0xba, 0x48, 0x09, 0xd0, 0x01, 0x01, 0x7a, 0x04, 0x10, 0x03, 0x18, 0x05, 0x48, 0x00, 0x52, 0x01, - 0x79, 0x12, 0x1e, 0x0a, 0x01, 0x7a, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x42, 0x0e, 0xba, 0x48, - 0x0b, 0xd0, 0x01, 0x01, 0x1a, 0x06, 0x18, 0x80, 0x02, 0x28, 0x80, 0x01, 0x48, 0x00, 0x52, 0x01, - 0x7a, 0x42, 0x03, 0x0a, 0x01, 0x6f, 0x42, 0xa2, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, 0x2e, 0x62, - 0x75, 0x66, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, - 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x42, 0x0b, 0x4f, - 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x53, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, - 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, - 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, - 0x65, 0x6e, 0x2f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, - 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, 0x73, 0x65, - 0x73, 0xa2, 0x02, 0x04, 0x42, 0x56, 0x43, 0x43, 0xaa, 0x02, 0x1e, 0x42, 0x75, 0x66, 0x2e, 0x56, - 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, - 0x6e, 0x63, 0x65, 0x2e, 0x43, 0x61, 0x73, 0x65, 0x73, 0xca, 0x02, 0x1e, 0x42, 0x75, 0x66, 0x5c, - 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, - 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0xe2, 0x02, 0x2a, 0x42, 0x75, 0x66, - 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, - 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x42, 0x75, 0x66, 0x3a, 0x3a, 0x56, - 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, - 0x61, 0x6e, 0x63, 0x65, 0x3a, 0x3a, 0x43, 0x61, 0x73, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x01, 0x42, 0xa2, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x75, 0x66, 0x2e, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, + 0x63, 0x65, 0x2e, 0x63, 0x61, 0x73, 0x65, 0x73, 0x42, 0x0b, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x73, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x53, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, + 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x62, 0x75, + 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x6f, + 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x63, 0x61, 0x73, 0x65, 0x73, 0xa2, 0x02, 0x04, 0x42, + 0x56, 0x43, 0x43, 0xaa, 0x02, 0x1e, 0x42, 0x75, 0x66, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, + 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x43, + 0x61, 0x73, 0x65, 0x73, 0xca, 0x02, 0x1e, 0x42, 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x5c, + 0x43, 0x61, 0x73, 0x65, 0x73, 0xe2, 0x02, 0x2a, 0x42, 0x75, 0x66, 0x5c, 0x56, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x5c, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, + 0x5c, 0x43, 0x61, 0x73, 0x65, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0xea, 0x02, 0x21, 0x42, 0x75, 0x66, 0x3a, 0x3a, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, + 0x74, 0x65, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x3a, + 0x3a, 0x43, 0x61, 0x73, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -623,14 +520,13 @@ func file_buf_validate_conformance_cases_oneofs_proto_rawDescGZIP() []byte { return file_buf_validate_conformance_cases_oneofs_proto_rawDescData } -var file_buf_validate_conformance_cases_oneofs_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_buf_validate_conformance_cases_oneofs_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_buf_validate_conformance_cases_oneofs_proto_goTypes = []interface{}{ (*TestOneofMsg)(nil), // 0: buf.validate.conformance.cases.TestOneofMsg (*OneofNone)(nil), // 1: buf.validate.conformance.cases.OneofNone (*Oneof)(nil), // 2: buf.validate.conformance.cases.Oneof (*OneofRequired)(nil), // 3: buf.validate.conformance.cases.OneofRequired (*OneofRequiredWithRequiredField)(nil), // 4: buf.validate.conformance.cases.OneofRequiredWithRequiredField - (*OneofIgnoreEmpty)(nil), // 5: buf.validate.conformance.cases.OneofIgnoreEmpty } var file_buf_validate_conformance_cases_oneofs_proto_depIdxs = []int32{ 0, // 0: buf.validate.conformance.cases.Oneof.z:type_name -> buf.validate.conformance.cases.TestOneofMsg @@ -707,18 +603,6 @@ func file_buf_validate_conformance_cases_oneofs_proto_init() { return nil } } - file_buf_validate_conformance_cases_oneofs_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*OneofIgnoreEmpty); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } } file_buf_validate_conformance_cases_oneofs_proto_msgTypes[1].OneofWrappers = []interface{}{ (*OneofNone_X)(nil), @@ -739,18 +623,13 @@ func file_buf_validate_conformance_cases_oneofs_proto_init() { (*OneofRequiredWithRequiredField_A)(nil), (*OneofRequiredWithRequiredField_B)(nil), } - file_buf_validate_conformance_cases_oneofs_proto_msgTypes[5].OneofWrappers = []interface{}{ - (*OneofIgnoreEmpty_X)(nil), - (*OneofIgnoreEmpty_Y)(nil), - (*OneofIgnoreEmpty_Z)(nil), - } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_buf_validate_conformance_cases_oneofs_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 5, NumExtensions: 0, NumServices: 0, }, diff --git a/tools/protovalidate-conformance/internal/cases/cases_ignore_empty.go b/tools/protovalidate-conformance/internal/cases/cases_ignore_empty.go index 1e42ccb2..11b0def0 100644 --- a/tools/protovalidate-conformance/internal/cases/cases_ignore_empty.go +++ b/tools/protovalidate-conformance/internal/cases/cases_ignore_empty.go @@ -192,5 +192,41 @@ func ignoreEmptySuite() suites.Suite { Message: &cases.IgnoreEmptyProto3Map{}, Expected: results.Success(true), }, + "proto3/repeated/items/zero": suites.Case{ + Message: &cases.IgnoreEmptyRepeatedItems{Val: []int32{0}}, + Expected: results.Success(true), + }, + "proto3/repeated/items/nonzero/valid": suites.Case{ + Message: &cases.IgnoreEmptyRepeatedItems{Val: []int32{1}}, + Expected: results.Success(true), + }, + "proto3/repeated/items/nonzero/invalid": suites.Case{ + Message: &cases.IgnoreEmptyRepeatedItems{Val: []int32{-1}}, + Expected: results.Violations(&validate.Violation{FieldPath: "val[0]", ConstraintId: "int32.gt"}), + }, + "proto3/map/keys/zero": suites.Case{ + Message: &cases.IgnoreEmptyMapPairs{Val: map[string]int32{"": 42}}, + Expected: results.Success(true), + }, + "proto3/map/keys/nonzero/valid": suites.Case{ + Message: &cases.IgnoreEmptyMapPairs{Val: map[string]int32{"foo": 42}}, + Expected: results.Success(true), + }, + "proto3/map/keys/nonzero/invalid": suites.Case{ + Message: &cases.IgnoreEmptyMapPairs{Val: map[string]int32{"x": 42}}, + Expected: results.Violations(&validate.Violation{FieldPath: `val["x"]`, ForKey: true, ConstraintId: "string.min_len"}), + }, + "proto3/map/values/zero": suites.Case{ + Message: &cases.IgnoreEmptyMapPairs{Val: map[string]int32{"foo": 0}}, + Expected: results.Success(true), + }, + "proto3/map/values/nonzero/valid": suites.Case{ + Message: &cases.IgnoreEmptyMapPairs{Val: map[string]int32{"foo": 42}}, + Expected: results.Success(true), + }, + "proto3/map/values/nonzero/invalid": suites.Case{ + Message: &cases.IgnoreEmptyMapPairs{Val: map[string]int32{"foo": -1}}, + Expected: results.Violations(&validate.Violation{FieldPath: `val["foo"]`, ConstraintId: "int32.gt"}), + }, } } diff --git a/tools/protovalidate-conformance/internal/cases/cases_oneof.go b/tools/protovalidate-conformance/internal/cases/cases_oneof.go index ed64a063..82f64b1f 100644 --- a/tools/protovalidate-conformance/internal/cases/cases_oneof.go +++ b/tools/protovalidate-conformance/internal/cases/cases_oneof.go @@ -95,17 +95,5 @@ func oneofSuite() suites.Suite { &validate.Violation{FieldPath: "o", ConstraintId: "required"}, &validate.Violation{FieldPath: "a", ConstraintId: "required"}), }, - "ignore_empty/X/valid": { - Message: &cases.OneofIgnoreEmpty{O: &cases.OneofIgnoreEmpty_X{X: ""}}, - Expected: results.Success(true), - }, - "ignore_empty/Y/valid": { - Message: &cases.OneofIgnoreEmpty{O: &cases.OneofIgnoreEmpty_Y{Y: []byte("")}}, - Expected: results.Success(true), - }, - "ignore_empty/Z/valid": { - Message: &cases.OneofIgnoreEmpty{O: &cases.OneofIgnoreEmpty_Z{Z: 0}}, - Expected: results.Success(true), - }, } }