Exemple #1
0
func (s *stringValidator) Validate(val interface{}) *Result {
	data := val.(string)

	if s.Required && (s.Default == nil || s.Default == "") {
		if err := validate.RequiredString(s.Path, s.In, data); err != nil {
			return sErr(err)
		}
	}

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

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

	if s.Pattern != "" {
		if err := validate.Pattern(s.Path, s.In, data, s.Pattern); err != nil {
			return sErr(err)
		}
	}
	return nil
}
Exemple #2
0
func (m *TaskCard) validateTitle(formats strfmt.Registry) error {

	if err := validate.RequiredString("title", "body", string(m.Title)); err != nil {
		return err
	}

	if err := validate.MinLength("title", "body", string(m.Title), 5); err != nil {
		return err
	}

	if err := validate.MaxLength("title", "body", string(m.Title), 150); err != nil {
		return err
	}

	return nil
}
Exemple #3
0
func (m *Milestone) validateName(formats strfmt.Registry) error {

	if err := validate.RequiredString("name", "body", string(m.Name)); err != nil {
		return err
	}

	if err := validate.MinLength("name", "body", string(m.Name), 3); err != nil {
		return err
	}

	if err := validate.MaxLength("name", "body", string(m.Name), 50); err != nil {
		return err
	}

	if err := validate.Pattern("name", "body", string(m.Name), `[A-Za-z][\w- ]+`); err != nil {
		return err
	}

	return nil
}
Exemple #4
0
func (m *UserCard) validateScreenName(formats strfmt.Registry) error {

	if err := validate.RequiredString("screenName", "body", string(m.ScreenName)); err != nil {
		return err
	}

	if err := validate.MinLength("screenName", "body", string(m.ScreenName), 3); err != nil {
		return err
	}

	if err := validate.MaxLength("screenName", "body", string(m.ScreenName), 255); err != nil {
		return err
	}

	if err := validate.Pattern("screenName", "body", string(m.ScreenName), `\w[\w_-]+`); err != nil {
		return err
	}

	return nil
}