Skip to content

Commit 5eb02cf

Browse files
smaye81nicksnyder
andauthored
Upgrade to Protovalidate v0.11.0 (#227)
This upgrades to the latest v0.11.0 release of Protovalidate. As a result, it conforms to the convention of using `rule` everywhere instead of `constraint`. All usages of `constraint` have been removed. In addition, this adds a few additional tests to the expected_failures list as a result of v0.11.0. Also, there are two failing unit tests as a result of the upgrade, which will be fixed in a follow-up as they seem to be related to the failing conformance tests. These failing unit tests are marked with a `TODO`. --------- Co-authored-by: Nick Snyder <[email protected]>
1 parent f6a8711 commit 5eb02cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2326
-1525
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ GO ?= go
1414
ARGS ?= --strict_message --strict_error
1515
GOLANGCI_LINT_VERSION ?= v1.64.8
1616
# Set to use a different version of protovalidate-conformance.
17-
# Should be kept in sync with the version referenced in proto/buf.lock and
17+
# 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.10.4
19+
CONFORMANCE_VERSION ?= v0.11.0
2020

2121
.PHONY: help
2222
help: ## Describe useful make targets

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![GoDoc](https://pkg.go.dev/badge/github.com/bufbuild/protovalidate-go.svg)](https://pkg.go.dev/github.com/bufbuild/protovalidate-go)
99
[![BSR](https://img.shields.io/badge/BSR-Module-0C65EC)][buf-mod]
1010

11-
[Protovalidate][protovalidate] provides standard annotations to validate common constraints on messages and fields, as well as the ability to use [CEL][cel] to write custom constraints. It's the next generation of [protoc-gen-validate][protoc-gen-validate], the only widely used validation library for Protobuf.
11+
[Protovalidate][protovalidate] provides standard annotations to validate common rules on messages and fields, as well as the ability to use [CEL][cel] to write custom rules. It's the next generation of [protoc-gen-validate][protoc-gen-validate], the only widely used validation library for Protobuf.
1212

1313
With Protovalidate, you can annotate your Protobuf messages with both standard and custom validation rules:
1414

any.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
//nolint:gochecknoglobals
2424
var (
25-
anyRuleDescriptor = (&validate.FieldConstraints{}).ProtoReflect().Descriptor().Fields().ByName("any")
25+
anyRuleDescriptor = (&validate.FieldRules{}).ProtoReflect().Descriptor().Fields().ByName("any")
2626
anyInRuleDescriptor = (&validate.AnyRules{}).ProtoReflect().Descriptor().Fields().ByName("in")
2727
anyInRulePath = &validate.FieldPath{
2828
Elements: []*validate.FieldPathElement{
@@ -66,10 +66,10 @@ func (a anyPB) Evaluate(_ protoreflect.Message, val protoreflect.Value, cfg *val
6666
if _, ok := a.In[typeURL]; !ok {
6767
err.Violations = append(err.Violations, &Violation{
6868
Proto: &validate.Violation{
69-
Field: a.base.fieldPath(),
70-
Rule: a.base.rulePath(anyInRulePath),
71-
ConstraintId: proto.String("any.in"),
72-
Message: proto.String("type URL must be in the allow list"),
69+
Field: a.base.fieldPath(),
70+
Rule: a.base.rulePath(anyInRulePath),
71+
RuleId: proto.String("any.in"),
72+
Message: proto.String("type URL must be in the allow list"),
7373
},
7474
FieldValue: val,
7575
FieldDescriptor: a.base.Descriptor,
@@ -86,10 +86,10 @@ func (a anyPB) Evaluate(_ protoreflect.Message, val protoreflect.Value, cfg *val
8686
if _, ok := a.NotIn[typeURL]; ok {
8787
err.Violations = append(err.Violations, &Violation{
8888
Proto: &validate.Violation{
89-
Field: a.base.fieldPath(),
90-
Rule: a.base.rulePath(anyNotInRulePath),
91-
ConstraintId: proto.String("any.not_in"),
92-
Message: proto.String("type URL must not be in the block list"),
89+
Field: a.base.fieldPath(),
90+
Rule: a.base.rulePath(anyNotInRulePath),
91+
RuleId: proto.String("any.not_in"),
92+
Message: proto.String("type URL must not be in the block list"),
9393
},
9494
FieldValue: val,
9595
FieldDescriptor: a.base.Descriptor,

ast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (set astSet) WithRuleValue(
134134
type compiledAST struct {
135135
AST *cel.Ast
136136
Env *cel.Env
137-
Source *validate.Constraint
137+
Source *validate.Rule
138138
Path []*validate.FieldPathElement
139139
Value protoreflect.Value
140140
Descriptor protoreflect.FieldDescriptor

ast_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestASTSet_ToProgramSet(t *testing.T) {
5454

5555
asts, err := compileASTs(
5656
expressions{
57-
Constraints: []*validate.Constraint{
57+
Rules: []*validate.Rule{
5858
{Expression: proto.String("foo")},
5959
},
6060
},
@@ -82,7 +82,7 @@ func TestASTSet_ReduceResiduals(t *testing.T) {
8282

8383
asts, err := compileASTs(
8484
expressions{
85-
Constraints: []*validate.Constraint{
85+
Rules: []*validate.Rule{
8686
{Expression: proto.String("foo")},
8787
},
8888
},

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
6-
- buf.build/bufbuild/protovalidate-testing
5+
- buf.build/bufbuild/protovalidate:v0.11.0
6+
- buf.build/bufbuild/protovalidate-testing:v0.11.0
77
- buf.build/envoyproxy/protoc-gen-validate
88
lint:
99
use:

0 commit comments

Comments
 (0)