Skip to content

Commit 80cf168

Browse files
srikrsna-bufjchadwick-buf
andauthored
Update protovalidate (#268)
This implements the following upstream changes: - bufbuild/protovalidate#397 - bufbuild/protovalidate#396 - bufbuild/protovalidate#394 --------- Signed-off-by: Sri Krishna <[email protected]> Co-authored-by: jchadwick-buf <[email protected]>
1 parent fd668f0 commit 80cf168

16 files changed

+2209
-10200
lines changed

.github/workflows/buf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ jobs:
3030
lint: true
3131
push: false
3232
archive: false
33+
breaking: false
3334
- name: Check Generate
3435
run: make checkgenerate

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GOLANGCI_LINT_VERSION ?= v2.1.2
1616
# Set to use a different version of protovalidate-conformance.
1717
# Should be kept in sync with the version referenced in buf.yaml and
1818
# 'buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go' in go.mod.
19-
CONFORMANCE_VERSION ?= v0.13.3
19+
CONFORMANCE_VERSION ?= v0.14.0
2020

2121
.PHONY: help
2222
help: ## Describe useful make targets
@@ -62,7 +62,7 @@ generate: generate-proto generate-license ## Regenerate code and license headers
6262
.PHONY: generate-proto
6363
generate-proto: $(BIN)/buf
6464
rm -rf internal/gen/*/
65-
$(BIN)/buf generate buf.build/bufbuild/protovalidate-testing:$(CONFORMANCE_VERSION)
65+
$(BIN)/buf generate https://github.com/bufbuild/protovalidate.git#branch=next,subdir=proto/protovalidate-testing
6666
$(BIN)/buf generate
6767

6868
.PHONY: generate-license

buf.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
version: v2
33
deps:
44
- name: buf.build/bufbuild/protovalidate
5-
commit: 9f2d3c737feb481a83375159c0733275
6-
digest: b5:19d3b83f7df2d284ff5935f4622d7f27e7464a93c210edb536e92a52bcc69b2a18da1312e96b5461601eba7b3764d5e90321bd62e6966870e7dbc2e4dedd98d6
5+
commit: d22d418d82d84932ba4ba554ce4208ca
6+
digest: b5:8b454cb411e14f0024bdb58ac2689aed2321e81617b61ef8a22c8147a7a9757eeb049ebfb899a699d37051bdb3251e172ba1c1ae2f5005d7c3f47a202109136a
77
- name: buf.build/bufbuild/protovalidate-testing
8-
commit: 64cb206b26e840bcaacabae7b19bdf33
9-
digest: b5:f0abbad11668a70061ec8870c8c6b71f56e033ff97e0c22264648504e9a9c9f636304a01e27485eeacf7256f9bf25abc48503836948609f537a0fbc136be839b
8+
commit: 3173472a3d1147cfb60458ad0cf16f2e
9+
digest: b5:628f7fd91082e885255bea51911e24ba3c92dbfdefd60960fb74224245ec00176ca2f19acd2bc5007b904c70d12b6bc95479f9aeb2f071632a3c20534fc78cca

buf.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: v2
22
modules:
33
- path: proto
44
deps:
5-
- buf.build/bufbuild/protovalidate:v0.13.3
6-
- buf.build/bufbuild/protovalidate-testing:v0.13.3
5+
- buf.build/bufbuild/protovalidate:v0.14.0
6+
- buf.build/bufbuild/protovalidate-testing:v0.14.0
77
lint:
88
use:
99
- STANDARD

builder.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ func (bldr *builder) buildMessage(
124124
cache messageCache,
125125
) {
126126
msgRules, _ := ResolveMessageRules(desc)
127-
if msgRules.GetDisabled() {
128-
return
129-
}
130127

131128
steps := []func(
132129
desc protoreflect.MessageDescriptor,
@@ -256,7 +253,7 @@ func (bldr *builder) buildField(
256253
) (field, error) {
257254
if fieldRules != nil && !fieldRules.HasIgnore() && isPartOfMessageOneof(msgRules, fieldDescriptor) {
258255
fieldRules = proto.CloneOf(fieldRules)
259-
fieldRules.SetIgnore(validate.Ignore_IGNORE_IF_UNPOPULATED)
256+
fieldRules.SetIgnore(validate.Ignore_IGNORE_IF_ZERO_VALUE)
260257
}
261258
fld := field{
262259
Value: value{
@@ -266,9 +263,6 @@ func (bldr *builder) buildField(
266263
Required: fieldRules.GetRequired(),
267264
Ignore: fieldRules.GetIgnore(),
268265
}
269-
if fld.shouldIgnoreDefault() {
270-
fld.Zero = bldr.zeroValue(fieldDescriptor, false)
271-
}
272266
err := bldr.buildValue(fieldDescriptor, fieldRules, &fld.Value, cache)
273267
return fld, err
274268
}
@@ -577,8 +571,7 @@ func (bldr *builder) shouldIgnoreAlways(rules *validate.FieldRules) bool {
577571
}
578572

579573
func (bldr *builder) shouldIgnoreEmpty(rules *validate.FieldRules) bool {
580-
return rules.GetIgnore() == validate.Ignore_IGNORE_IF_UNPOPULATED ||
581-
rules.GetIgnore() == validate.Ignore_IGNORE_IF_DEFAULT_VALUE
574+
return rules.GetIgnore() == validate.Ignore_IGNORE_IF_ZERO_VALUE
582575
}
583576

584577
func (bldr *builder) zeroValue(fdesc protoreflect.FieldDescriptor, forItems bool) protoreflect.Value {

field.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ type field struct {
4242
HasPresence bool
4343
// Whether validation should be ignored for certain conditions.
4444
Ignore validate.Ignore
45-
// Zero is the default or zero-value for this value's type
46-
Zero protoreflect.Value
4745
// Err stores if there was a compilation error constructing this evaluator. It is stored
4846
// here so that it can be returned as part of validating this specific field.
4947
Err error
@@ -59,13 +57,7 @@ func (f field) shouldIgnoreAlways() bool {
5957
// This field is generally true for nullable fields or fields with the
6058
// ignore_empty rule explicitly set.
6159
func (f field) shouldIgnoreEmpty() bool {
62-
return f.HasPresence || f.Ignore == validate.Ignore_IGNORE_IF_UNPOPULATED || f.Ignore == validate.Ignore_IGNORE_IF_DEFAULT_VALUE
63-
}
64-
65-
// shouldIgnoreDefault returns whether this field should skip validation on its zero value,
66-
// including for fields which have field presence and are set to the zero value.
67-
func (f field) shouldIgnoreDefault() bool {
68-
return f.HasPresence && f.Ignore == validate.Ignore_IGNORE_IF_DEFAULT_VALUE
60+
return f.HasPresence || f.Ignore == validate.Ignore_IGNORE_IF_ZERO_VALUE
6961
}
7062

7163
func (f field) Evaluate(_ protoreflect.Message, val protoreflect.Value, cfg *validationConfig) error {
@@ -103,11 +95,7 @@ func (f field) EvaluateMessage(msg protoreflect.Message, cfg *validationConfig)
10395
return nil
10496
}
10597

106-
val := msg.Get(f.Value.Descriptor)
107-
if f.shouldIgnoreDefault() && val.Equal(f.Zero) {
108-
return nil
109-
}
110-
return f.Value.EvaluateField(msg, val, cfg, true)
98+
return f.Value.EvaluateField(msg, msg.Get(f.Value.Descriptor), cfg, true)
11199
}
112100

113101
func (f field) Tautology() bool {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module buf.build/go/protovalidate
33
go 1.23.0
44

55
require (
6-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250625184727-c923a0c2a132.1
6+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250717165733-d22d418d82d8.1
77
github.com/google/cel-go v0.25.0
88
github.com/stretchr/testify v1.10.0
99
google.golang.org/protobuf v1.36.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250625184727-c923a0c2a132.1 h1:6tCo3lsKNLqUjRPhyc8JuYWYUiQkulufxSDOfG1zgWQ=
2-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250625184727-c923a0c2a132.1/go.mod h1:avRlCjnFzl98VPaeCtJ24RrV/wwHFzB8sWXhj26+n/U=
1+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250717165733-d22d418d82d8.1 h1:VahIvw/JagkamVOb0q87Az0zu2tmrzlqvO2IKIGOwnI=
2+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250717165733-d22d418d82d8.1/go.mod h1:avRlCjnFzl98VPaeCtJ24RrV/wwHFzB8sWXhj26+n/U=
33
cel.dev/expr v0.23.1 h1:K4KOtPCJQjVggkARsjG9RWXP6O4R73aHeJMa/dmCQQg=
44
cel.dev/expr v0.23.1/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
55
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=

0 commit comments

Comments
 (0)