// Common validation for all build functions except Tranport.
423019
func validateConfigFunc(t reflect.Type, outputType reflect.Type) error {
	switch {
	case t.Kind() != reflect.Func:
		return errors.New("must be a function")
	case t.NumIn() != 3:
		return fmt.Errorf("must accept exactly three arguments, found %v", t.NumIn())
	case !isDecodable(t.In(0)):
		return fmt.Errorf("must accept a struct or struct pointer as its first argument, found %v", t.In(0))
	case t.In(1) != _typeOfTransport:
		// TODO: We can make this smarter by making transport.Transport
		// optional and either the first or the second argument instead of
		// requiring it as the second argument.
		return fmt.Errorf("must accept a transport.Transport as its second argument, found %v", t.In(1))
	case t.In(2) != _typeOfKit:
		return fmt.Errorf("must accept a %v as its third argument, found %v", _typeOfKit, t.In(2))
	case t.NumOut() != 2:
		return fmt.Errorf("must return exactly two results, found %v", t.NumOut())
	case t.Out(0) != outputType:
		return fmt.Errorf("must return a %v as its first result, found %v", outputType, t.Out(0))
	case t.Out(1) != _typeOfError:
		return fmt.Errorf("must return an error as its second result, found %v", t.Out(1))
	}

	return nil
}
41923
func (id BuildID) Validate() error {
	switch {
	case id.Master == "":
		return errors.New("master is unspecified", grpcutil.InvalidArgumentTag)
	case id.Builder == "":
		return errors.New("builder is unspecified", grpcutil.InvalidArgumentTag)
	case id.Number < 0:
		return errors.New("nunber must be >= 0", grpcutil.InvalidArgumentTag)
	default:
		return nil
	}
}
341911
func buildTransport(cv *buildable, k *Kit) (transport.Transport, error) {
	result, err := cv.Build(k)
	if err != nil {
		return nil, err
	}
	return result.(transport.Transport), nil
}
302431
func Convert_v1_Build_To_build_Build(in *v1.Build, out *build.Build, s conversion.Scope) error {
	return autoConvert_v1_Build_To_build_Build(in, out, s)
}
387287
func (apiDef *APIDefinition) allTraits(trts map[string]Trait, libraries map[string]*Library) map[string]Trait {
	if len(trts) == 0 {
		trts = map[string]Trait{}
	}
	for libName, l := range libraries {
		for trtName, trt := range l.Traits {
			trts[libName+"."+trtName] = trt
		}
		// Recursively processing siblings
		if l.Libraries != nil {
			apiDef.allTraits(trts, l.Libraries)
		}
	}
	return trts
}
217265
func (cfg *Config) Validate(c *validation.Context) {
	if cfg.GetProject() == "" {
		c.Errorf("project is required")
	}
	if cfg.GetRevision() != "" {
		c.Errorf("revision must not be specified")
	}
}
1260675
func (m *GrpcJsonTranscoder) Validate() error {
	if m == nil {
		return nil
	}

	if len(m.GetServices()) < 1 {
		return GrpcJsonTranscoderValidationError{
			field:  "Services",
			reason: "value must contain at least 1 item(s)",
		}
	}

	{
		tmp := m.GetPrintOptions()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return GrpcJsonTranscoderValidationError{
					field:  "PrintOptions",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	// no validation rules for MatchIncomingRequestRoute

	switch m.DescriptorSet.(type) {

	case *GrpcJsonTranscoder_ProtoDescriptor:
		// no validation rules for ProtoDescriptor

	case *GrpcJsonTranscoder_ProtoDescriptorBin:
		// no validation rules for ProtoDescriptorBin

	default:
		return GrpcJsonTranscoderValidationError{
			field:  "DescriptorSet",
			reason: "value is required",
		}

	}

	return nil
}
1211290
func (c *Config) CommonExcludes(excludes []string) {
	for i, b := range c.Blocks {
		if !b.NoCommonFilter {
			b.Exclude = append(b.Exclude, excludes...)
		}
		c.Blocks[i] = b
	}
}
1275524
func (c *constraint) check(v *Version) bool {
	return c.function(v, c)
}
23568
func (d *DefaultLoader) MustValidate(conf interface{}) {
	if err := d.Validate(conf); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}
}
1080786
func (gm serverMethod) ReqBodyNeedValidation() bool {
	// we can't use t.GetBuiltinType here because
	// the reqBody type is already in Go type
	getBuiltinType := func() string {
		switch {
		case strings.HasPrefix(gm.reqBody, "[][]"): // bidimensional array
			return strings.TrimPrefix(gm.reqBody, "[][]")
		case strings.HasPrefix(gm.reqBody, "[]"): // array
			return strings.TrimPrefix(gm.reqBody, "[]")
		default:
			return gm.reqBody
		}
	}
	t := raml.Type{
		Type: getBuiltinType(),
	}

	return !t.IsBuiltin()
}
731531
func (o *StartBuildOptions) Validate() error {
	if o.AsBinary {
		if len(o.LogLevel) > 0 {
			fmt.Fprintf(o.ErrOut, "WARNING: Specifying --build-loglevel with binary builds is not supported.\n")
		}
		if len(o.EnvVar) > 1 || (len(o.LogLevel) == 0 && len(o.EnvVar) > 0) {
			fmt.Fprintf(o.ErrOut, "WARNING: Specifying environment variables with binary builds is not supported.\n")
		}
		if len(o.BuildArgs) > 0 {
			fmt.Fprintf(o.ErrOut, "WARNING: Specifying build arguments with binary builds is not supported.\n")
		}
	}

	if len(o.FromBuild) != 0 && o.AsBinary {
		// TODO: we should support this, it should be possible to clone a build to run again with new uploaded artifacts.
		// Doing so requires introducing a new clonebinary endpoint.
		return fmt.Errorf("cannot use '--from-build' flag with binary builds")
	}

	if len(o.Name) == 0 && len(o.FromWebhook) == 0 && len(o.FromBuild) == 0 {
		return fmt.Errorf("a resource name is required either as an argument or by using --from-build")
	}

	if len(o.ListWebhooks) > 0 {
		switch o.ListWebhooks {
		case "all":
		case "generic":
		case "github":
			// do nothing
		default:
			return fmt.Errorf("--list-webhooks must be 'all', 'generic', or 'github'")
		}
	}

	return nil
}
1122320
func (v *Validator) Compile() (*jsval.JSVal, error) {
	b := builder.New()
	jsv, err := b.Build(v.schema)
	if err != nil {
		return nil, errors.Wrap(err, "failed to build validator")
	}
	return jsv, nil
}
1235141
func (b *codeGenOpBuilder) HasValidations(sh spec.CommonValidations, rt resolvedType) (hasValidations bool, hasSliceValidations bool) {
	// TODO: exclude format byte (istrfmt.Base64) from validation (issue#1548)
	hasNumberValidation := sh.Maximum != nil || sh.Minimum != nil || sh.MultipleOf != nil
	hasStringValidation := sh.MaxLength != nil || sh.MinLength != nil || sh.Pattern != ""
	hasSliceValidations = sh.MaxItems != nil || sh.MinItems != nil || sh.UniqueItems || len(sh.Enum) > 0
	hasValidations = (hasNumberValidation || hasStringValidation || hasSliceValidations || rt.IsCustomFormatter) && !rt.IsStream && !rt.IsInterface
	return
}
746415
func (v *Validate) RegisterStructValidation(fn StructLevelFunc, types ...interface{}) {
	v.RegisterStructValidationCtx(wrapStructLevelFunc(fn), types...)
}
1016433
func AssertStructValid(c interface{}) error {
	ct := reflect.TypeOf(c)
	cv := reflect.ValueOf(c)
	for i := 0; i < ct.NumField(); i++ {
		ft := ct.Field(i)
		if !isFieldExported(ft) {
			continue
		}

		if err := AssertValid(cv.Field(i), ft.Tag.Get("valid")); err != nil {
			err.Field = ft.Name
			return err
		}
	}
	return nil
}
636014
func (o *OnlyExcept) Validate(t *Template) error {
	if len(o.Only) > 0 && len(o.Except) > 0 {
		return errors.New("only one of 'only' or 'except' may be specified")
	}

	var err error
	for _, n := range o.Only {
		if _, ok := t.Builders[n]; !ok {
			err = multierror.Append(err, fmt.Errorf(
				"'only' specified builder '%s' not found", n))
		}
	}
	for _, n := range o.Except {
		if _, ok := t.Builders[n]; !ok {
			err = multierror.Append(err, fmt.Errorf(
				"'except' specified builder '%s' not found", n))
		}
	}

	return err
}