Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ lint:
PROTOVALIDATE:
- proto/tests/example/v1/validations.proto
- proto/tests/example/v1/filter.proto
- proto/tests/example/v1/compile.proto
breaking:
use:
- FILE
7 changes: 2 additions & 5 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ func (bldr *builder) buildMessage(
}

for _, step := range steps {
if step(desc, msgConstraints, msgEval, cache); msgEval.Err != nil {
break
}
step(desc, msgConstraints, msgEval, cache)
}
}

Expand Down Expand Up @@ -200,8 +198,7 @@ func (bldr *builder) processFields(
fieldConstraints := resolve.FieldConstraints(fdesc)
fldEval, err := bldr.buildField(fdesc, fieldConstraints, cache)
if err != nil {
msgEval.Err = err
return
fldEval.Err = err
}
msgEval.AppendNested(fldEval)
}
Expand Down
9 changes: 8 additions & 1 deletion field.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type field struct {
IgnoreDefault bool
// Zero is the default or zero-value for this value's type
Zero protoreflect.Value
// Err stores if there was a compilation error constructing this evaluator. It is stored
// here so that it can be returned as part of validating this specific field.
Err error
}

func (f field) Evaluate(_ protoreflect.Message, val protoreflect.Value, cfg *validationConfig) error {
Expand All @@ -57,6 +60,10 @@ func (f field) EvaluateMessage(msg protoreflect.Message, cfg *validationConfig)
return nil
}

if f.Err != nil {
return f.Err
}

if f.Required && !msg.Has(f.Value.Descriptor) {
return &ValidationError{Violations: []*Violation{{
Proto: &validate.Violation{
Expand Down Expand Up @@ -84,7 +91,7 @@ func (f field) EvaluateMessage(msg protoreflect.Message, cfg *validationConfig)
}

func (f field) Tautology() bool {
return !f.Required && f.Value.Tautology()
return !f.Required && f.Value.Tautology() && f.Err == nil
}

var _ messageEvaluator = field{}
261 changes: 261 additions & 0 deletions internal/gen/tests/example/v1/compile.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading