Пример #1
0
func (m *TaskCard) validateTags(formats strfmt.Registry) error {

	if swag.IsZero(m.Tags) { // not required
		return nil
	}

	iTagsSize := int64(len(m.Tags))

	if err := validate.MaxItems("tags", "body", iTagsSize, 5); err != nil {
		return err
	}

	if err := validate.UniqueItems("tags", "body", m.Tags); err != nil {
		return err
	}

	for i := 0; i < len(m.Tags); i++ {

		if err := validate.RequiredString("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i])); err != nil {
			return err
		}

		if err := validate.MinLength("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i]), 3); err != nil {
			return err
		}

		if err := validate.Pattern("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i]), `\w[\w- ]+`); err != nil {
			return err
		}

	}

	return nil
}
func (m *RepositoryBuildRequest) validateDockerTags(formats strfmt.Registry) error {

	if swag.IsZero(m.DockerTags) { // not required
		return nil
	}

	iDockerTagsSize := int64(len(m.DockerTags))

	if err := validate.MinItems("docker_tags", "body", iDockerTagsSize, 1); err != nil {
		return err
	}

	if err := validate.UniqueItems("docker_tags", "body", m.DockerTags); err != nil {
		return err
	}

	for i := 0; i < len(m.DockerTags); i++ {

		if err := validate.RequiredString("docker_tags"+"."+strconv.Itoa(i), "body", string(m.DockerTags[i])); err != nil {
			return err
		}

	}

	return nil
}
Пример #3
0
func (o *ListTasksParams) validateTags(formats strfmt.Registry) error {

	if err := validate.UniqueItems("tags", "query", o.Tags); err != nil {
		return err
	}

	return nil
}
Пример #4
0
func (s *schemaSliceValidator) Validate(data interface{}) *Result {
	result := new(Result)
	if data == nil {
		return result
	}
	val := reflect.ValueOf(data)
	size := val.Len()

	if s.Items != nil && s.Items.Schema != nil {
		validator := NewSchemaValidator(s.Items.Schema, s.Root, s.Path, s.KnownFormats)
		for i := 0; i < size; i++ {
			validator.SetPath(fmt.Sprintf("%s.%d", s.Path, i))
			value := val.Index(i)
			result.Merge(validator.Validate(value.Interface()))
		}
	}

	itemsSize := int64(0)
	if s.Items != nil && len(s.Items.Schemas) > 0 {
		itemsSize = int64(len(s.Items.Schemas))
		for i := int64(0); i < itemsSize; i++ {
			validator := NewSchemaValidator(&s.Items.Schemas[i], s.Root, fmt.Sprintf("%s.%d", s.Path, i), s.KnownFormats)
			result.Merge(validator.Validate(val.Index(int(i)).Interface()))
		}

	}
	if s.AdditionalItems != nil && itemsSize < int64(size) {
		if s.Items != nil && len(s.Items.Schemas) > 0 && !s.AdditionalItems.Allows {
			result.AddErrors(errors.New(422, "array doesn't allow for additional items"))
		}
		if s.AdditionalItems.Schema != nil {
			for i := itemsSize; i < (int64(size)-itemsSize)+1; i++ {
				validator := NewSchemaValidator(s.AdditionalItems.Schema, s.Root, fmt.Sprintf("%s.%d", s.Path, i), s.KnownFormats)
				result.Merge(validator.Validate(val.Index(int(i)).Interface()))
			}
		}
	}

	if s.MinItems != nil {
		if err := validate.MinItems(s.Path, s.In, int64(size), *s.MinItems); err != nil {
			result.AddErrors(err)
		}
	}
	if s.MaxItems != nil {
		if err := validate.MaxItems(s.Path, s.In, int64(size), *s.MaxItems); err != nil {
			result.AddErrors(err)
		}
	}
	if s.UniqueItems {
		if err := validate.UniqueItems(s.Path, s.In, val.Interface()); err != nil {
			result.AddErrors(err)
		}
	}
	result.Inc()
	return result
}
Пример #5
0
func (m *RepositoryBuildRequest) validateDockerTags(formats strfmt.Registry) error {

	iDockerTagsSize := int64(len(m.DockerTags))

	if err := validate.MinItems("docker_tags", "body", iDockerTagsSize, 1); err != nil {
		return err
	}

	if err := validate.UniqueItems("docker_tags", "body", m.DockerTags); err != nil {
		return err
	}

	return nil
}
Пример #6
0
func (s *basicSliceValidator) Validate(data interface{}) *Result {
	val := reflect.ValueOf(data)

	size := int64(val.Len())
	if s.MinItems != nil {
		if err := validate.MinItems(s.Path, s.In, size, *s.MinItems); err != nil {
			return sErr(err)
		}
	}

	if s.MaxItems != nil {
		if err := validate.MaxItems(s.Path, s.In, size, *s.MaxItems); err != nil {
			return sErr(err)
		}
	}

	if s.UniqueItems {
		if err := validate.UniqueItems(s.Path, s.In, data); err != nil {
			return sErr(err)
		}
	}

	if s.itemsValidator == nil && s.Items != nil {
		s.itemsValidator = newItemsValidator(s.Path, s.In, s.Items, s.Source, s.KnownFormats)
	}

	if s.itemsValidator != nil {
		for i := 0; i < int(size); i++ {
			ele := val.Index(i)
			if err := s.itemsValidator.Validate(i, ele.Interface()); err != nil && err.HasErrors() {
				return err
			}
		}
	}
	return nil
}