func (m *ResourcePolicy) Validate() error {
	if m == nil {
		return nil
	}
	if utf8.RuneCountInString(m.GetResource()) < 1 {
		return ResourcePolicyValidationError{
			field:  "Resource",
			reason: "value length must be at least 1 runes",
		}
	}
	if !_ResourcePolicy_Resource_Pattern.MatchString(m.GetResource()) {
		return ResourcePolicyValidationError{
			field:  "Resource",
			reason: "value does not match regex pattern \"^[[:alpha:]][[:word:]\\\\@\\\\.\\\\-/]*(\\\\:[[:alpha:]][[:word:]\\\\@\\\\.\\\\-/]*)*$\"",
		}
	}
	if !_ResourcePolicy_Version_Pattern.MatchString(m.GetVersion()) {
		return ResourcePolicyValidationError{
			field:  "Version",
			reason: "value does not match regex pattern \"^[[:word:]]+$\"",
		}
	}
	_ResourcePolicy_ImportDerivedRoles_Unique := make(map[string]struct{}, len(m.GetImportDerivedRoles()))
	for idx, item := range m.GetImportDerivedRoles() {
		_, _ = idx, item
		if _, exists := _ResourcePolicy_ImportDerivedRoles_Unique[item]; exists {
			return ResourcePolicyValidationError{
				field:  fmt.Sprintf("ImportDerivedRoles[%v]", idx),
				reason: "repeated value must contain unique items",
			}
		} else {
			_ResourcePolicy_ImportDerivedRoles_Unique[item] = struct{}{}
		}
		if !_ResourcePolicy_ImportDerivedRoles_Pattern.MatchString(item) {
			return ResourcePolicyValidationError{
				field:  fmt.Sprintf("ImportDerivedRoles[%v]", idx),
				reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
			}
		}
	}
	if len(m.GetRules()) < 1 {
		return ResourcePolicyValidationError{
			field:  "Rules",
			reason: "value must contain at least 1 item(s)",
		}
	}
	for idx, item := range m.GetRules() {
		_, _ = idx, item
		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return ResourcePolicyValidationError{
					field:  fmt.Sprintf("Rules[%v]", idx),
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}
	if !_ResourcePolicy_Scope_Pattern.MatchString(m.GetScope()) {
		return ResourcePolicyValidationError{
			field:  "Scope",
			reason: "value does not match regex pattern \"^([[:alpha:]][[:word:]\\\\-]+(\\\\.[[:alpha:]][[:word:]\\\\-]*)*)*$\"",
		}
	}
	return nil
}
Validate checks the field values on ResourcePolicy with the rules defined in
the proto definition for this message. If any rules are violated, an error
is returned.
package policyv1
import (
	"bytes"
	"errors"
	"fmt"
	"net"
	"net/mail"
	"net/url"
	"regexp"
	"strings"
	"time"
	"unicode/utf8"
	"google.golang.org/protobuf/types/known/anypb"
	effectv1 "github.com/cerbos/cerbos/api/genpb/cerbos/effect/v1"
)
var (
	_ = bytes.MinRead
	_ = errors.New("")
	_ = fmt.Print
	_ = utf8.UTFMax
	_ = (*regexp.Regexp)(nil)
	_ = (*strings.Reader)(nil)
	_ = net.IPv4len
	_ = time.Duration(0)
	_ = (*url.URL)(nil)
	_ = (*mail.Address)(nil)
	_ = anypb.Any{}
	_ = effectv1.Effect(0)
	_ = effectv1.Effect(0)
)
func (m *Policy) Validate() error {
	if m == nil {
		return nil
	}
	if m.GetApiVersion() != "api.cerbos.dev/v1" {
		return PolicyValidationError{
			field:  "ApiVersion",
			reason: "value must equal api.cerbos.dev/v1",
		}
	}
	if v, ok := interface{}(m.GetMetadata()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return PolicyValidationError{
				field:  "Metadata",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}
	switch m.PolicyType.(type) {
	case *Policy_ResourcePolicy:
		if v, ok := interface{}(m.GetResourcePolicy()).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PolicyValidationError{
					field:  "ResourcePolicy",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	case *Policy_PrincipalPolicy:
		if v, ok := interface{}(m.GetPrincipalPolicy()).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PolicyValidationError{
					field:  "PrincipalPolicy",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	case *Policy_DerivedRoles:
		if v, ok := interface{}(m.GetDerivedRoles()).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PolicyValidationError{
					field:  "DerivedRoles",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	default:
		return PolicyValidationError{
			field:  "PolicyType",
			reason: "value is required",
		}
	}
	return nil
}
type PolicyValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e PolicyValidationError) Field() string { return e.field }
func (e PolicyValidationError) Reason() string { return e.reason }
func (e PolicyValidationError) Cause() error { return e.cause }
func (e PolicyValidationError) Key() bool { return e.key }
func (e PolicyValidationError) ErrorName() string { return "PolicyValidationError" }
func (e PolicyValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}
	key := ""
	if e.key {
		key = "key for "
	}
	return fmt.Sprintf(
		"invalid %sPolicy.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = PolicyValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = PolicyValidationError{}
func (m *Metadata) Validate() error {
	if m == nil {
		return nil
	}
	return nil
}
type MetadataValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e MetadataValidationError) Field() string { return e.field }
func (e MetadataValidationError) Reason() string { return e.reason }
func (e MetadataValidationError) Cause() error { return e.cause }
func (e MetadataValidationError) Key() bool { return e.key }
func (e MetadataValidationError) ErrorName() string { return "MetadataValidationError" }
func (e MetadataValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}
	key := ""
	if e.key {
		key = "key for "
	}
	return fmt.Sprintf(
		"invalid %sMetadata.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = MetadataValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = MetadataValidationError{}