From 451a7c2f421c7ab516405162279bc47e04ef253d Mon Sep 17 00:00:00 2001 From: wxz <1769475169@qq.com> Date: Fri, 14 Jun 2024 00:49:41 +0800 Subject: [PATCH] Fix support for repeated int64 inclusion check (#1122) https://github.com/bufbuild/protoc-gen-validate/issues/1121 --- templates/goshared/msg.go | 14 ++++++++++++++ validate/validate.pb.go | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/templates/goshared/msg.go b/templates/goshared/msg.go index 030b94bce..98657f495 100644 --- a/templates/goshared/msg.go +++ b/templates/goshared/msg.go @@ -200,6 +200,20 @@ var _ interface{ {{- end }} } {{ end }}{{ end }} + {{ if has .Rules.Items.GetInt64 "In" }} {{ if .Rules.Items.GetInt64.In }} + var {{ lookup .Field "InLookup" }} = map[int64]struct{}{ + {{- range .Rules.Items.GetInt64.In }} + {{ inKey $f . }}: {}, + {{- end }} + } + {{ end }}{{ end }} + {{ if has .Rules.Items.GetInt64 "NotIn" }} {{ if .Rules.Items.GetInt64.NotIn }} + var {{ lookup .Field "NotInLookup" }} = map[int64]struct{}{ + {{- range .Rules.Items.GetInt64.NotIn }} + {{ inKey $f . }}: {}, + {{- end }} + } + {{ end }}{{ end }} {{ if has .Rules.Items.GetAny "In" }} {{ if .Rules.Items.GetAny.In }} var {{ lookup .Field "InLookup" }} = map[string]struct{}{ {{- range .Rules.Items.GetAny.In }} diff --git a/validate/validate.pb.go b/validate/validate.pb.go index a31b2e1a3..6df95e89e 100644 --- a/validate/validate.pb.go +++ b/validate/validate.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v4.22.2 +// protoc v3.21.12 // source: validate/validate.proto package validate @@ -1974,7 +1974,7 @@ type StringRules struct { // MaxBytes specifies that this field must be the specified number of bytes // at a maximum MaxBytes *uint64 `protobuf:"varint,5,opt,name=max_bytes,json=maxBytes" json:"max_bytes,omitempty"` - // Pattern specifes that this field must match against the specified + // Pattern specifies that this field must match against the specified // regular expression (RE2 syntax). The included expression should elide // any delimiters. Pattern *string `protobuf:"bytes,6,opt,name=pattern" json:"pattern,omitempty"` @@ -2349,7 +2349,7 @@ type BytesRules struct { // MaxLen specifies that this field must be the specified number of bytes // at a maximum MaxLen *uint64 `protobuf:"varint,3,opt,name=max_len,json=maxLen" json:"max_len,omitempty"` - // Pattern specifes that this field must match against the specified + // Pattern specifies that this field must match against the specified // regular expression (RE2 syntax). The included expression should elide // any delimiters. Pattern *string `protobuf:"bytes,4,opt,name=pattern" json:"pattern,omitempty"` @@ -2699,10 +2699,10 @@ type RepeatedRules struct { // items at a maximum MaxItems *uint64 `protobuf:"varint,2,opt,name=max_items,json=maxItems" json:"max_items,omitempty"` // Unique specifies that all elements in this field must be unique. This - // contraint is only applicable to scalar and enum types (messages are not + // constraint is only applicable to scalar and enum types (messages are not // supported). Unique *bool `protobuf:"varint,3,opt,name=unique" json:"unique,omitempty"` - // Items specifies the contraints to be applied to each item in the field. + // Items specifies the constraints to be applied to each item in the field. // Repeated message fields will still execute validation against each item // unless skip is specified here. Items *FieldRules `protobuf:"bytes,4,opt,name=items" json:"items,omitempty"`