// Validate validates the given value against this Constraint
8273
func (c *ArrayConstraint) Validate(v interface{}) (err error) {
	if pdebug.Enabled {
		g := pdebug.IPrintf("START ArrayConstraint.Validate")
		defer func() {
			if err == nil {
				g.IRelease("END ArrayConstraint.Validate (PASS)")
			} else {
				g.IRelease("END ArrayConstraint.Validate (FAIL): %s", err)
			}
		}()
	}

	rv := reflect.ValueOf(v)
	switch rv.Kind() {
	case reflect.Slice:
	default:
		var typ string
		if rv == zeroval {
			typ = "invalid"
		} else {
			typ = rv.Type().String()
		}
		return errors.New("value must be a slice (was: " + typ + ")")
	}

	l := rv.Len()

	if mi := c.minItems; mi > -1 && l < mi {
		return errors.New("fewer items than minItems")
	}

	if mi := c.maxItems; mi > -1 && l > mi {
		return errors.New("more items than maxItems")
	}

	var uitems map[string]struct{}
	if c.uniqueItems {
		pdebug.Printf("Check for unique items enabled")
		uitems = make(map[string]struct{})
		for i := 0; i < l; i++ {
			iv := rv.Index(i).Interface()
			kv := fmt.Sprintf("%s", iv)
pdebug.Printf("unique? -> %s", kv)
			if _, ok := uitems[kv]; ok {
				return errors.New("duplicate element found")
			}
			uitems[kv] = struct{}{}
		}
	}

	if celem := c.items; celem != nil {
		if pdebug.Enabled {
			pdebug.Printf("Checking if all items match a spec")
		}
		// if this is set, then all items must fulfill this.
		// additional items are ignored
		for i := 0; i < l; i++ {
			iv := rv.Index(i).Interface()
			if err := celem.Validate(iv); err != nil {
				return err
			}
		}
	} else {
		// otherwise, check the positional specs, and apply the
		// additionalItems constraint
		lv := rv.Len()
		for i, cpos := range c.positionalItems {
			if lv <= i {
				break
			}
			if pdebug.Enabled {
				pdebug.Printf("Checking positional item at '%d'", i)
			}
			iv := rv.Index(i).Interface()
			if err := cpos.Validate(iv); err != nil {
				return err
			}
		}

		lp := len(c.positionalItems)
		if lp > 0 && l > lp { // we got more than positional schemas
			cadd := c.additionalItems
			if cadd == nil { // you can't have additionalItems!
				return errors.New("additional elements found in array")
			}
			for i := lp - 1; i < l; i++ {
				iv := rv.Index(i).Interface()
				if err := cadd.Validate(iv); err != nil {
					return err
				}
			}
		}
	}
	return nil
}
1111145
func (v *Validator) Validate(x interface{}) error {
	jsv, err := v.validator()
	if err != nil {
		return err
	}
	return jsv.Validate(x)
}
1199112
func (c *ControllerConfig) Validate() error {
	if c.Changes == nil {
		return errors.NotValidf("nil Changes")
	}
	return nil
}
1355651
func (*DoubleSchema) Validate(v reflect.Value) bool {
	return reflect.TypeOf(dereference(v).Interface()).Kind() == reflect.Float64
}
815458
func (m *ThresholdTrigger) Validate() error {
	if m == nil {
		return nil
	}

	if val := m.GetValue(); val < 0 || val > 1 {
		return ThresholdTriggerValidationError{
			field:  "Value",
			reason: "value must be inside range [0, 1]",
		}
	}

	return nil
}
611675
func (m *Config_KeyValuePair) Validate() error {
	if m == nil {
		return nil
	}

	// no validation rules for MetadataNamespace

	if len(m.GetKey()) < 1 {
		return Config_KeyValuePairValidationError{
			field:  "Key",
			reason: "value length must be at least 1 bytes",
		}
	}

	// no validation rules for Value

	// no validation rules for Type

	return nil
}
45658
func (s *StringRule) Validate(cv ctypes.ConfigValue) error {
	// Check that type is correct
	if cv.Type() != StringType {
		return wrongType(s.key, cv.Type(), StringType)
	}
	return nil
}
90111
func (*StringSchema) Validate(v reflect.Value) bool {
	_, ok := dereference(v).Interface().(string)
	return ok
}
564021
func (p *Number) Validate() error {
	if p.Int8 != nil {
		p.Variant = NumberVariantInt8
	} else if p.Int16 != nil {
		p.Variant = NumberVariantInt16
	} else if p.Int32 != nil {
		p.Variant = NumberVariantInt32
	} else if p.Int64 != nil {
		p.Variant = NumberVariantInt64
	} else if p.Float32 != nil {
		p.Variant = NumberVariantFloat32
	} else if p.Float64 != nil {
		p.Variant = NumberVariantFloat64
	} else {
		return fmt.Errorf("Number: Missing required variant")
	}
	return nil
}
211756
func (m *StringMatcher) Validate() error {
	if m == nil {
		return nil
	}

	switch m.MatchPattern.(type) {

	case *StringMatcher_Exact:
		// no validation rules for Exact

	case *StringMatcher_Prefix:

		if len(m.GetPrefix()) < 1 {
			return StringMatcherValidationError{
				field:  "Prefix",
				reason: "value length must be at least 1 bytes",
			}
		}

	case *StringMatcher_Suffix:

		if len(m.GetSuffix()) < 1 {
			return StringMatcherValidationError{
				field:  "Suffix",
				reason: "value length must be at least 1 bytes",
			}
		}

	case *StringMatcher_Regex:

		if len(m.GetRegex()) > 1024 {
			return StringMatcherValidationError{
				field:  "Regex",
				reason: "value length must be at most 1024 bytes",
			}
		}

	default:
		return StringMatcherValidationError{
			field:  "MatchPattern",
			reason: "value is required",
		}

	}

	return nil
}
171348
func (m *FaultRateLimit_FixedLimit) Validate() error {
	if m == nil {
		return nil
	}

	if m.GetLimitKbps() < 1 {
		return FaultRateLimit_FixedLimitValidationError{
			field:  "LimitKbps",
			reason: "value must be greater than or equal to 1",
		}
	}

	return nil
}
36235
func Validate(schema *Schema, typename string, data interface{}) Validation {
	v := getValidator(schema)
	return validateWithValidator(v, typename, data)
}
1043783
func (v *StringRule) Validate(value interface{}) error {
	value, isNil := Indirect(value)
	if isNil || IsEmpty(value) {
		return nil
	}

	str, err := EnsureString(value)
	if err != nil {
		return err
	}

	if v.validate(str) {
		return nil
	}
	return errors.New(v.message)
}
572102
func (minmax *MinMax) Validate() error {
	// Instances["min"] and Instances["max"] must be positive
	if minmax.Min < 0 || minmax.Max < 0 {
		return fmt.Errorf("Instances constraints must be positive: Min=%v; Max=%v", minmax.Min, minmax.Max)
	}

	// If "min" and "max" are both declared Instances["min"] < Instances["max"]
	if minmax.Max != 0 && minmax.Min > minmax.Max {
		return fmt.Errorf("Minimum instances larger than maximum instances: Min=%v; Max=%v", minmax.Min, minmax.Max)
	}

	// "Default" should be between min + max, inclusive if max is nonzero and default is set
	if minmax.Default != 0 {
		if minmax.Max != 0 {
			if minmax.Default < minmax.Min || minmax.Default > minmax.Max {
				return fmt.Errorf("Default instance spec must be between min and max, inclusive: Min=%v; Max=%v; Default=%v", minmax.Min, minmax.Max, minmax.Default)
			}
		} else {
			if minmax.Default < minmax.Min {
				return fmt.Errorf("Default instance spec cannot be less than the minimum: Min=%v; Max=%v; Default=%v", minmax.Min, minmax.Max, minmax.Default)
			}
		}
	}
	return nil
}
157414
func (constraints *tokenConstraints) validate() (err error) {
	keys := 0
	if constraints.key != nil {
		keys++
	}
	if constraints.secret != "" {
		keys++
	}
	if keys > 1 {
		err = fmt.Errorf("duplicate key constraints")
		return
	}
	if keys < 1 {
		err = fmt.Errorf("no key constraint")
		return
	}
	return
}
84039
func (c *AnyConstraint) Validate(v interface{}) (err error) {
	if pdebug.Enabled {
		g := pdebug.Marker("AnyConstraint.Validate").BindError(&err)
		defer g.End()
	}
	for _, celem := range c.constraints {
		if err := celem.Validate(v); err == nil {
			return nil
		}
	}
	return errors.New("could not validate against any of the constraints")
}
556336
func (c Code) Validate(_ interface{}) error {
	if codeRegex.Match([]byte(c)) {
		return nil
	}

	return errInvalidCode
}