Skip to content

Commit

Permalink
Add ResolvePredefinedConstraints method to DefaultResolver (#151)
Browse files Browse the repository at this point in the history
This method is not really needed by protovalidate itself, but it is
really convenient for us to implement and really inconvenient for
consumers to implement, especially if they want to mimic the reparsing
logic of protovalidate-go.

Fixes #147.
  • Loading branch information
jchadwick-buf authored Oct 2, 2024
1 parent 1ca4047 commit 88c8cca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ func (r DefaultResolver) ResolveOneofConstraints(desc protoreflect.OneofDescript
func (r DefaultResolver) ResolveFieldConstraints(desc protoreflect.FieldDescriptor) *validate.FieldConstraints {
return extensions.Resolve[*validate.FieldConstraints](desc.Options(), validate.E_Field)
}

// ResolvePredefinedConstraints returns the PredefinedConstraints option set for
// the FieldDescriptor. Note that this value is only meaningful if it is set on
// a field or extension of a field rule message. This method is provided for
// convenience.
func (r DefaultResolver) ResolvePredefinedConstraints(desc protoreflect.FieldDescriptor) *validate.PredefinedConstraints {
return extensions.Resolve[*validate.PredefinedConstraints](desc.Options(), validate.E_Predefined)
}

0 comments on commit 88c8cca

Please sign in to comment.