Esempio n. 1
0
// Validate validates the media type instance.
func (mt *Series) Validate() (err error) {
	if mt.Account.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.Account.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_at`, mt.Account.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if mt.Account.CreatedBy != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Account.CreatedBy); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_by`, mt.Account.CreatedBy, goa.FormatEmail, err2, err)
		}
	}
	if mt.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(mt.Name) < 2 {
		err = goa.InvalidLengthError(`response.name`, mt.Name, 2, true, err)
	}
	if mt.UpdatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.UpdatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.updated_at`, mt.UpdatedAt, goa.FormatDateTime, err2, err)
		}
	}
	return
}
Esempio n. 2
0
// Validate validates the media type instance.
func (mt SeriesCollection) Validate() (err error) {
	for _, e := range mt {
		if e.Account.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.Account.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].account.created_at`, e.Account.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if e.Account.CreatedBy != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, e.Account.CreatedBy); err2 != nil {
				err = goa.InvalidFormatError(`response[*].account.created_by`, e.Account.CreatedBy, goa.FormatEmail, err2, err)
			}
		}
		if e.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].created_at`, e.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(e.Name) < 2 {
			err = goa.InvalidLengthError(`response[*].name`, e.Name, 2, true, err)
		}
		if e.UpdatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.UpdatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].updated_at`, e.UpdatedAt, goa.FormatDateTime, err2, err)
			}
		}
	}
	return
}
Esempio n. 3
0
// Dump produces raw data from an instance of Account running all the
// validations. See LoadAccount for the definition of raw data.
func (mt *Account) Dump(view AccountViewEnum) (map[string]interface{}, error) {
	var err error
	var res map[string]interface{}
	if view == AccountDefaultView {
		if mt.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`default view.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if mt.CreatedBy != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, mt.CreatedBy); err2 != nil {
				err = goa.InvalidFormatError(`default view.created_by`, mt.CreatedBy, goa.FormatEmail, err2, err)
			}
		}
		tmp27 := map[string]interface{}{
			"created_at": mt.CreatedAt,
			"created_by": mt.CreatedBy,
			"href":       mt.Href,
			"id":         mt.ID,
			"name":       mt.Name,
		}
		res = tmp27
	}
	if view == AccountLinkView {
		tmp28 := map[string]interface{}{
			"href": mt.Href,
			"id":   mt.ID,
			"name": mt.Name,
		}
		res = tmp28
	}
	return res, err
}
Esempio n. 4
0
// Dump produces raw data from an instance of UserCollection running all the
// validations. See LoadUserCollection for the definition of raw data.
func (mt UserCollection) Dump() ([]map[string]interface{}, error) {
	var err error
	var res []map[string]interface{}
	res = make([]map[string]interface{}, len(mt))
	for i, tmp69 := range mt {
		if tmp69.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp69.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`default view[*].created_at`, tmp69.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if tmp69.Email != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, tmp69.Email); err2 != nil {
				err = goa.InvalidFormatError(`default view[*].email`, tmp69.Email, goa.FormatEmail, err2, err)
			}
		}
		tmp70 := map[string]interface{}{
			"created_at": tmp69.CreatedAt,
			"email":      tmp69.Email,
			"first_name": tmp69.FirstName,
			"href":       tmp69.Href,
			"id":         tmp69.ID,
			"last_name":  tmp69.LastName,
		}
		res[i] = tmp70
	}
	return res, err
}
Esempio n. 5
0
// Validate validates the media type instance.
func (mt *User) Validate() (err error) {
	if mt.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if mt.Email != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Email); err2 != nil {
			err = goa.InvalidFormatError(`response.email`, mt.Email, goa.FormatEmail, err2, err)
		}
	}
	return
}
Esempio n. 6
0
// Validate validates the media type instance.
func (mt *Account) Validate() (err error) {
	if mt.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if mt.CreatedBy != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, mt.CreatedBy); err2 != nil {
			err = goa.InvalidFormatError(`response.created_by`, mt.CreatedBy, goa.FormatEmail, err2, err)
		}
	}
	return
}
Esempio n. 7
0
// Validate validates the media type instance.
func (mt UserCollection) Validate() (err error) {
	for _, e := range mt {
		if e.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].created_at`, e.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if e.Email != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, e.Email); err2 != nil {
				err = goa.InvalidFormatError(`response[*].email`, e.Email, goa.FormatEmail, err2, err)
			}
		}
	}
	return
}
Esempio n. 8
0
// Dump produces raw data from an instance of User running all the
// validations. See LoadUser for the definition of raw data.
func (mt *User) Dump(view UserViewEnum) (map[string]interface{}, error) {
	var err error
	var res map[string]interface{}
	if view == UserDefaultView {
		if mt.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`default view.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if mt.Email != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Email); err2 != nil {
				err = goa.InvalidFormatError(`default view.email`, mt.Email, goa.FormatEmail, err2, err)
			}
		}
		tmp60 := map[string]interface{}{
			"created_at": mt.CreatedAt,
			"email":      mt.Email,
			"first_name": mt.FirstName,
			"href":       mt.Href,
			"id":         mt.ID,
			"last_name":  mt.LastName,
		}
		res = tmp60
	}
	if view == UserLinkView {
		if mt.Email != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Email); err2 != nil {
				err = goa.InvalidFormatError(`link view.email`, mt.Email, goa.FormatEmail, err2, err)
			}
		}
		tmp61 := map[string]interface{}{
			"email": mt.Email,
			"href":  mt.Href,
			"id":    mt.ID,
		}
		res = tmp61
	}
	return res, err
}
Esempio n. 9
0
// MarshalAccount validates and renders an instance of Account into a interface{}
// using view "default".
func MarshalAccount(source *Account, inErr error) (target map[string]interface{}, err error) {
	err = inErr
	if source.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, source.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`.created_at`, source.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if source.CreatedBy != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, source.CreatedBy); err2 != nil {
			err = goa.InvalidFormatError(`.created_by`, source.CreatedBy, goa.FormatEmail, err2, err)
		}
	}
	tmp22 := map[string]interface{}{
		"created_at": source.CreatedAt,
		"created_by": source.CreatedBy,
		"href":       source.Href,
		"id":         source.ID,
		"name":       source.Name,
	}
	target = tmp22
	return
}
Esempio n. 10
0
// LoadUserCollection loads raw data into an instance of UserCollection running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadUserCollection(raw interface{}) (UserCollection, error) {
	var err error
	var res UserCollection
	if val, ok := raw.([]interface{}); ok {
		res = make([]*User, len(val))
		for i, v := range val {
			var tmp62 *User
			if val, ok := v.(map[string]interface{}); ok {
				tmp62 = new(User)
				if v, ok := val["created_at"]; ok {
					var tmp63 string
					if val, ok := v.(string); ok {
						tmp63 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].CreatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp63 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp63); err2 != nil {
								err = goa.InvalidFormatError(`[*].CreatedAt`, tmp63, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp62.CreatedAt = tmp63
				}
				if v, ok := val["email"]; ok {
					var tmp64 string
					if val, ok := v.(string); ok {
						tmp64 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Email`, v, "string", err)
					}
					if err == nil {
						if tmp64 != "" {
							if err2 := goa.ValidateFormat(goa.FormatEmail, tmp64); err2 != nil {
								err = goa.InvalidFormatError(`[*].Email`, tmp64, goa.FormatEmail, err2, err)
							}
						}
					}
					tmp62.Email = tmp64
				}
				if v, ok := val["first_name"]; ok {
					var tmp65 string
					if val, ok := v.(string); ok {
						tmp65 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].FirstName`, v, "string", err)
					}
					tmp62.FirstName = tmp65
				}
				if v, ok := val["href"]; ok {
					var tmp66 string
					if val, ok := v.(string); ok {
						tmp66 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Href`, v, "string", err)
					}
					tmp62.Href = tmp66
				}
				if v, ok := val["id"]; ok {
					var tmp67 int
					if f, ok := v.(float64); ok {
						tmp67 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].ID`, v, "int", err)
					}
					tmp62.ID = tmp67
				}
				if v, ok := val["last_name"]; ok {
					var tmp68 string
					if val, ok := v.(string); ok {
						tmp68 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].LastName`, v, "string", err)
					}
					tmp62.LastName = tmp68
				}
			} else {
				err = goa.InvalidAttributeTypeError(`[*]`, v, "map[string]interface{}", err)
			}
			res[i] = tmp62
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "[]interface{}", err)
	}
	return res, err
}
Esempio n. 11
0
// LoadUser loads raw data into an instance of User running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadUser(raw interface{}) (*User, error) {
	var err error
	var res *User
	if val, ok := raw.(map[string]interface{}); ok {
		res = new(User)
		if v, ok := val["created_at"]; ok {
			var tmp54 string
			if val, ok := v.(string); ok {
				tmp54 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp54 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp54); err2 != nil {
						err = goa.InvalidFormatError(`.CreatedAt`, tmp54, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.CreatedAt = tmp54
		}
		if v, ok := val["email"]; ok {
			var tmp55 string
			if val, ok := v.(string); ok {
				tmp55 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Email`, v, "string", err)
			}
			if err == nil {
				if tmp55 != "" {
					if err2 := goa.ValidateFormat(goa.FormatEmail, tmp55); err2 != nil {
						err = goa.InvalidFormatError(`.Email`, tmp55, goa.FormatEmail, err2, err)
					}
				}
			}
			res.Email = tmp55
		}
		if v, ok := val["first_name"]; ok {
			var tmp56 string
			if val, ok := v.(string); ok {
				tmp56 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.FirstName`, v, "string", err)
			}
			res.FirstName = tmp56
		}
		if v, ok := val["href"]; ok {
			var tmp57 string
			if val, ok := v.(string); ok {
				tmp57 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Href`, v, "string", err)
			}
			res.Href = tmp57
		}
		if v, ok := val["id"]; ok {
			var tmp58 int
			if f, ok := v.(float64); ok {
				tmp58 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.ID`, v, "int", err)
			}
			res.ID = tmp58
		}
		if v, ok := val["last_name"]; ok {
			var tmp59 string
			if val, ok := v.(string); ok {
				tmp59 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.LastName`, v, "string", err)
			}
			res.LastName = tmp59
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "map[string]interface{}", err)
	}
	return res, err
}
Esempio n. 12
0
// UnmarshalAccount unmarshals and validates a raw interface{} into an instance of Account
func UnmarshalAccount(source interface{}, inErr error) (target *Account, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(Account)
		if v, ok := val["created_at"]; ok {
			var tmp24 string
			if val, ok := v.(string); ok {
				tmp24 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp24 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp24); err2 != nil {
						err = goa.InvalidFormatError(`load.CreatedAt`, tmp24, goa.FormatDateTime, err2, err)
					}
				}
			}
			target.CreatedAt = tmp24
		}
		if v, ok := val["created_by"]; ok {
			var tmp25 string
			if val, ok := v.(string); ok {
				tmp25 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.CreatedBy`, v, "string", err)
			}
			if err == nil {
				if tmp25 != "" {
					if err2 := goa.ValidateFormat(goa.FormatEmail, tmp25); err2 != nil {
						err = goa.InvalidFormatError(`load.CreatedBy`, tmp25, goa.FormatEmail, err2, err)
					}
				}
			}
			target.CreatedBy = tmp25
		}
		if v, ok := val["href"]; ok {
			var tmp26 string
			if val, ok := v.(string); ok {
				tmp26 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Href`, v, "string", err)
			}
			target.Href = tmp26
		}
		if v, ok := val["id"]; ok {
			var tmp27 int
			if f, ok := v.(float64); ok {
				tmp27 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.ID`, v, "int", err)
			}
			target.ID = tmp27
		}
		if v, ok := val["name"]; ok {
			var tmp28 string
			if val, ok := v.(string); ok {
				tmp28 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Name`, v, "string", err)
			}
			target.Name = tmp28
		}
	} else {
		err = goa.InvalidAttributeTypeError(`load`, source, "dictionary", err)
	}
	return
}
Esempio n. 13
0
// UnmarshalBottle unmarshals and validates a raw interface{} into an instance of Bottle
func UnmarshalBottle(source interface{}, inErr error) (target *Bottle, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(Bottle)
		if v, ok := val["account"]; ok {
			var tmp32 *Account
			tmp32, err = UnmarshalAccount(v, err)
			target.Account = tmp32
		}
		if v, ok := val["color"]; ok {
			var tmp33 string
			if val, ok := v.(string); ok {
				tmp33 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Color`, v, "string", err)
			}
			if err == nil {
				if tmp33 != "" {
					if !(tmp33 == "red" || tmp33 == "white" || tmp33 == "rose" || tmp33 == "yellow" || tmp33 == "sparkling") {
						err = goa.InvalidEnumValueError(`load.Color`, tmp33, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
					}
				}
			}
			target.Color = tmp33
		}
		if v, ok := val["country"]; ok {
			var tmp34 string
			if val, ok := v.(string); ok {
				tmp34 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Country`, v, "string", err)
			}
			if err == nil {
				if len(tmp34) < 2 {
					err = goa.InvalidLengthError(`load.Country`, tmp34, len(tmp34), 2, true, err)
				}
			}
			target.Country = tmp34
		}
		if v, ok := val["created_at"]; ok {
			var tmp35 string
			if val, ok := v.(string); ok {
				tmp35 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp35 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp35); err2 != nil {
						err = goa.InvalidFormatError(`load.CreatedAt`, tmp35, goa.FormatDateTime, err2, err)
					}
				}
			}
			target.CreatedAt = tmp35
		}
		if v, ok := val["href"]; ok {
			var tmp36 string
			if val, ok := v.(string); ok {
				tmp36 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Href`, v, "string", err)
			}
			target.Href = tmp36
		}
		if v, ok := val["id"]; ok {
			var tmp37 int
			if f, ok := v.(float64); ok {
				tmp37 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.ID`, v, "int", err)
			}
			target.ID = tmp37
		}
		if v, ok := val["name"]; ok {
			var tmp38 string
			if val, ok := v.(string); ok {
				tmp38 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Name`, v, "string", err)
			}
			if err == nil {
				if len(tmp38) < 2 {
					err = goa.InvalidLengthError(`load.Name`, tmp38, len(tmp38), 2, true, err)
				}
			}
			target.Name = tmp38
		}
		if v, ok := val["rating"]; ok {
			var tmp39 int
			if f, ok := v.(float64); ok {
				tmp39 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.Rating`, v, "int", err)
			}
			if err == nil {
				if tmp39 < 1 {
					err = goa.InvalidRangeError(`load.Rating`, tmp39, 1, true, err)
				}
				if tmp39 > 5 {
					err = goa.InvalidRangeError(`load.Rating`, tmp39, 5, false, err)
				}
			}
			target.Rating = tmp39
		}
		if v, ok := val["region"]; ok {
			var tmp40 string
			if val, ok := v.(string); ok {
				tmp40 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Region`, v, "string", err)
			}
			target.Region = tmp40
		}
		if v, ok := val["review"]; ok {
			var tmp41 string
			if val, ok := v.(string); ok {
				tmp41 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Review`, v, "string", err)
			}
			if err == nil {
				if len(tmp41) < 10 {
					err = goa.InvalidLengthError(`load.Review`, tmp41, len(tmp41), 10, true, err)
				}
				if len(tmp41) > 300 {
					err = goa.InvalidLengthError(`load.Review`, tmp41, len(tmp41), 300, false, err)
				}
			}
			target.Review = tmp41
		}
		if v, ok := val["sweetness"]; ok {
			var tmp42 int
			if f, ok := v.(float64); ok {
				tmp42 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.Sweetness`, v, "int", err)
			}
			if err == nil {
				if tmp42 < 1 {
					err = goa.InvalidRangeError(`load.Sweetness`, tmp42, 1, true, err)
				}
				if tmp42 > 5 {
					err = goa.InvalidRangeError(`load.Sweetness`, tmp42, 5, false, err)
				}
			}
			target.Sweetness = tmp42
		}
		if v, ok := val["updated_at"]; ok {
			var tmp43 string
			if val, ok := v.(string); ok {
				tmp43 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.UpdatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp43 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp43); err2 != nil {
						err = goa.InvalidFormatError(`load.UpdatedAt`, tmp43, goa.FormatDateTime, err2, err)
					}
				}
			}
			target.UpdatedAt = tmp43
		}
		if v, ok := val["varietal"]; ok {
			var tmp44 string
			if val, ok := v.(string); ok {
				tmp44 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Varietal`, v, "string", err)
			}
			if err == nil {
				if len(tmp44) < 4 {
					err = goa.InvalidLengthError(`load.Varietal`, tmp44, len(tmp44), 4, true, err)
				}
			}
			target.Varietal = tmp44
		}
		if v, ok := val["vineyard"]; ok {
			var tmp45 string
			if val, ok := v.(string); ok {
				tmp45 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Vineyard`, v, "string", err)
			}
			if err == nil {
				if len(tmp45) < 2 {
					err = goa.InvalidLengthError(`load.Vineyard`, tmp45, len(tmp45), 2, true, err)
				}
			}
			target.Vineyard = tmp45
		}
		if v, ok := val["vintage"]; ok {
			var tmp46 int
			if f, ok := v.(float64); ok {
				tmp46 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.Vintage`, v, "int", err)
			}
			if err == nil {
				if tmp46 < 1900 {
					err = goa.InvalidRangeError(`load.Vintage`, tmp46, 1900, true, err)
				}
				if tmp46 > 2020 {
					err = goa.InvalidRangeError(`load.Vintage`, tmp46, 2020, false, err)
				}
			}
			target.Vintage = tmp46
		}
	} else {
		err = goa.InvalidAttributeTypeError(`load`, source, "dictionary", err)
	}
	return
}
Esempio n. 14
0
// LoadAccount loads raw data into an instance of Account running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadAccount(raw interface{}) (*Account, error) {
	var err error
	var res *Account
	if val, ok := raw.(map[string]interface{}); ok {
		res = new(Account)
		if v, ok := val["created_at"]; ok {
			var tmp22 string
			if val, ok := v.(string); ok {
				tmp22 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp22 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp22); err2 != nil {
						err = goa.InvalidFormatError(`.CreatedAt`, tmp22, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.CreatedAt = tmp22
		}
		if v, ok := val["created_by"]; ok {
			var tmp23 string
			if val, ok := v.(string); ok {
				tmp23 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.CreatedBy`, v, "string", err)
			}
			if err == nil {
				if tmp23 != "" {
					if err2 := goa.ValidateFormat(goa.FormatEmail, tmp23); err2 != nil {
						err = goa.InvalidFormatError(`.CreatedBy`, tmp23, goa.FormatEmail, err2, err)
					}
				}
			}
			res.CreatedBy = tmp23
		}
		if v, ok := val["href"]; ok {
			var tmp24 string
			if val, ok := v.(string); ok {
				tmp24 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Href`, v, "string", err)
			}
			res.Href = tmp24
		}
		if v, ok := val["id"]; ok {
			var tmp25 int
			if f, ok := v.(float64); ok {
				tmp25 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.ID`, v, "int", err)
			}
			res.ID = tmp25
		}
		if v, ok := val["name"]; ok {
			var tmp26 string
			if val, ok := v.(string); ok {
				tmp26 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Name`, v, "string", err)
			}
			res.Name = tmp26
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "map[string]interface{}", err)
	}
	return res, err
}
Esempio n. 15
0
// Dump produces raw data from an instance of Series running all the
// validations. See LoadSeries for the definition of raw data.
func (mt *Series) Dump(view SeriesViewEnum) (map[string]interface{}, error) {
	var err error
	var res map[string]interface{}
	if view == SeriesDefaultView {
		if len(mt.Name) < 2 {
			err = goa.InvalidLengthError(`default view.name`, mt.Name, 2, true, err)
		}
		tmp30 := map[string]interface{}{
			"href": mt.Href,
			"id":   mt.ID,
			"name": mt.Name,
		}
		res = tmp30
		if err == nil {
			links := make(map[string]interface{})
			tmp29 := map[string]interface{}{
				"href": mt.Account.Href,
				"id":   mt.Account.ID,
				"name": mt.Account.Name,
			}
			links["account"] = tmp29
			res["links"] = links
		}
	}
	if view == SeriesFullView {
		if mt.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`full view.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(mt.Name) < 2 {
			err = goa.InvalidLengthError(`full view.name`, mt.Name, 2, true, err)
		}
		if mt.UpdatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.UpdatedAt); err2 != nil {
				err = goa.InvalidFormatError(`full view.updated_at`, mt.UpdatedAt, goa.FormatDateTime, err2, err)
			}
		}
		tmp32 := map[string]interface{}{
			"created_at": mt.CreatedAt,
			"href":       mt.Href,
			"id":         mt.ID,
			"name":       mt.Name,
			"updated_at": mt.UpdatedAt,
		}
		if mt.Account != nil {
			if mt.Account.CreatedAt != "" {
				if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.Account.CreatedAt); err2 != nil {
					err = goa.InvalidFormatError(`full view.Account.created_at`, mt.Account.CreatedAt, goa.FormatDateTime, err2, err)
				}
			}
			if mt.Account.CreatedBy != "" {
				if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Account.CreatedBy); err2 != nil {
					err = goa.InvalidFormatError(`full view.Account.created_by`, mt.Account.CreatedBy, goa.FormatEmail, err2, err)
				}
			}
			tmp33 := map[string]interface{}{
				"created_at": mt.Account.CreatedAt,
				"created_by": mt.Account.CreatedBy,
				"href":       mt.Account.Href,
				"id":         mt.Account.ID,
				"name":       mt.Account.Name,
			}
			tmp32["account"] = tmp33
		}
		res = tmp32
		if err == nil {
			links := make(map[string]interface{})
			tmp31 := map[string]interface{}{
				"href": mt.Account.Href,
				"id":   mt.Account.ID,
				"name": mt.Account.Name,
			}
			links["account"] = tmp31
			res["links"] = links
		}
	}
	if view == SeriesTinyView {
		if len(mt.Name) < 2 {
			err = goa.InvalidLengthError(`tiny view.name`, mt.Name, 2, true, err)
		}
		tmp35 := map[string]interface{}{
			"href": mt.Href,
			"id":   mt.ID,
			"name": mt.Name,
		}
		res = tmp35
		if err == nil {
			links := make(map[string]interface{})
			tmp34 := map[string]interface{}{
				"href": mt.Account.Href,
				"id":   mt.Account.ID,
				"name": mt.Account.Name,
			}
			links["account"] = tmp34
			res["links"] = links
		}
	}
	return res, err
}
Esempio n. 16
0
// LoadSeries loads raw data into an instance of Series running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadSeries(raw interface{}) (*Series, error) {
	var err error
	var res *Series
	if val, ok := raw.(map[string]interface{}); ok {
		res = new(Series)
		if v, ok := val["account"]; ok {
			var tmp18 *Account
			if val, ok := v.(map[string]interface{}); ok {
				tmp18 = new(Account)
				if v, ok := val["created_at"]; ok {
					var tmp19 string
					if val, ok := v.(string); ok {
						tmp19 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.CreatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp19 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp19); err2 != nil {
								err = goa.InvalidFormatError(`.Account.CreatedAt`, tmp19, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp18.CreatedAt = tmp19
				}
				if v, ok := val["created_by"]; ok {
					var tmp20 string
					if val, ok := v.(string); ok {
						tmp20 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.CreatedBy`, v, "string", err)
					}
					if err == nil {
						if tmp20 != "" {
							if err2 := goa.ValidateFormat(goa.FormatEmail, tmp20); err2 != nil {
								err = goa.InvalidFormatError(`.Account.CreatedBy`, tmp20, goa.FormatEmail, err2, err)
							}
						}
					}
					tmp18.CreatedBy = tmp20
				}
				if v, ok := val["href"]; ok {
					var tmp21 string
					if val, ok := v.(string); ok {
						tmp21 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.Href`, v, "string", err)
					}
					tmp18.Href = tmp21
				}
				if v, ok := val["id"]; ok {
					var tmp22 int
					if f, ok := v.(float64); ok {
						tmp22 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.ID`, v, "int", err)
					}
					tmp18.ID = tmp22
				}
				if v, ok := val["name"]; ok {
					var tmp23 string
					if val, ok := v.(string); ok {
						tmp23 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.Name`, v, "string", err)
					}
					tmp18.Name = tmp23
				}
			} else {
				err = goa.InvalidAttributeTypeError(`.Account`, v, "map[string]interface{}", err)
			}
			res.Account = tmp18
		}
		if v, ok := val["created_at"]; ok {
			var tmp24 string
			if val, ok := v.(string); ok {
				tmp24 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp24 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp24); err2 != nil {
						err = goa.InvalidFormatError(`.CreatedAt`, tmp24, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.CreatedAt = tmp24
		}
		if v, ok := val["href"]; ok {
			var tmp25 string
			if val, ok := v.(string); ok {
				tmp25 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Href`, v, "string", err)
			}
			res.Href = tmp25
		}
		if v, ok := val["id"]; ok {
			var tmp26 int
			if f, ok := v.(float64); ok {
				tmp26 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.ID`, v, "int", err)
			}
			res.ID = tmp26
		}
		if v, ok := val["name"]; ok {
			var tmp27 string
			if val, ok := v.(string); ok {
				tmp27 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Name`, v, "string", err)
			}
			if err == nil {
				if len(tmp27) < 2 {
					err = goa.InvalidLengthError(`.Name`, tmp27, 2, true, err)
				}
			}
			res.Name = tmp27
		}
		if v, ok := val["updated_at"]; ok {
			var tmp28 string
			if val, ok := v.(string); ok {
				tmp28 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.UpdatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp28 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp28); err2 != nil {
						err = goa.InvalidFormatError(`.UpdatedAt`, tmp28, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.UpdatedAt = tmp28
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "map[string]interface{}", err)
	}
	return res, err
}
Esempio n. 17
0
// Validate validates the media type instance.
func (mt BottleCollection) Validate() (err error) {
	for _, e := range mt {
		if e.Account.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.Account.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].account.created_at`, e.Account.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if e.Account.CreatedBy != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, e.Account.CreatedBy); err2 != nil {
				err = goa.InvalidFormatError(`response[*].account.created_by`, e.Account.CreatedBy, goa.FormatEmail, err2, err)
			}
		}
		if e.Color != "" {
			if !(e.Color == "red" || e.Color == "white" || e.Color == "rose" || e.Color == "yellow" || e.Color == "sparkling") {
				err = goa.InvalidEnumValueError(`response[*].color`, e.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
			}
		}
		if len(e.Country) < 2 {
			err = goa.InvalidLengthError(`response[*].country`, e.Country, len(e.Country), 2, true, err)
		}
		if e.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].created_at`, e.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(e.Name) < 2 {
			err = goa.InvalidLengthError(`response[*].name`, e.Name, len(e.Name), 2, true, err)
		}
		if e.Rating < 1 {
			err = goa.InvalidRangeError(`response[*].rating`, e.Rating, 1, true, err)
		}
		if e.Rating > 5 {
			err = goa.InvalidRangeError(`response[*].rating`, e.Rating, 5, false, err)
		}
		if len(e.Review) < 10 {
			err = goa.InvalidLengthError(`response[*].review`, e.Review, len(e.Review), 10, true, err)
		}
		if len(e.Review) > 300 {
			err = goa.InvalidLengthError(`response[*].review`, e.Review, len(e.Review), 300, false, err)
		}
		if e.Sweetness < 1 {
			err = goa.InvalidRangeError(`response[*].sweetness`, e.Sweetness, 1, true, err)
		}
		if e.Sweetness > 5 {
			err = goa.InvalidRangeError(`response[*].sweetness`, e.Sweetness, 5, false, err)
		}
		if e.UpdatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.UpdatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].updated_at`, e.UpdatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(e.Varietal) < 4 {
			err = goa.InvalidLengthError(`response[*].varietal`, e.Varietal, len(e.Varietal), 4, true, err)
		}
		if len(e.Vineyard) < 2 {
			err = goa.InvalidLengthError(`response[*].vineyard`, e.Vineyard, len(e.Vineyard), 2, true, err)
		}
		if e.Vintage < 1900 {
			err = goa.InvalidRangeError(`response[*].vintage`, e.Vintage, 1900, true, err)
		}
		if e.Vintage > 2020 {
			err = goa.InvalidRangeError(`response[*].vintage`, e.Vintage, 2020, false, err)
		}
	}
	return
}
Esempio n. 18
0
// Validate validates the media type instance.
func (mt *Bottle) Validate() (err error) {
	if mt.Account.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.Account.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_at`, mt.Account.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if mt.Account.CreatedBy != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Account.CreatedBy); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_by`, mt.Account.CreatedBy, goa.FormatEmail, err2, err)
		}
	}
	if mt.Color != "" {
		if !(mt.Color == "red" || mt.Color == "white" || mt.Color == "rose" || mt.Color == "yellow" || mt.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`response.color`, mt.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if len(mt.Country) < 2 {
		err = goa.InvalidLengthError(`response.country`, mt.Country, 2, true, err)
	}
	if mt.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(mt.Name) < 2 {
		err = goa.InvalidLengthError(`response.name`, mt.Name, 2, true, err)
	}
	if mt.Rating < 1 {
		err = goa.InvalidRangeError(`response.rating`, mt.Rating, 1, true, err)
	}
	if mt.Rating > 5 {
		err = goa.InvalidRangeError(`response.rating`, mt.Rating, 5, false, err)
	}
	if len(mt.Review) < 10 {
		err = goa.InvalidLengthError(`response.review`, mt.Review, 10, true, err)
	}
	if len(mt.Review) > 300 {
		err = goa.InvalidLengthError(`response.review`, mt.Review, 300, false, err)
	}
	if mt.Sweetness < 1 {
		err = goa.InvalidRangeError(`response.sweetness`, mt.Sweetness, 1, true, err)
	}
	if mt.Sweetness > 5 {
		err = goa.InvalidRangeError(`response.sweetness`, mt.Sweetness, 5, false, err)
	}
	if mt.UpdatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.UpdatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.updated_at`, mt.UpdatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(mt.Varietal) < 4 {
		err = goa.InvalidLengthError(`response.varietal`, mt.Varietal, 4, true, err)
	}
	if len(mt.Vineyard) < 2 {
		err = goa.InvalidLengthError(`response.vineyard`, mt.Vineyard, 2, true, err)
	}
	if mt.Vintage < 1900 {
		err = goa.InvalidRangeError(`response.vintage`, mt.Vintage, 1900, true, err)
	}
	if mt.Vintage > 2020 {
		err = goa.InvalidRangeError(`response.vintage`, mt.Vintage, 2020, false, err)
	}
	return
}
Esempio n. 19
0
// LoadBottle loads raw data into an instance of Bottle running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadBottle(raw interface{}) (*Bottle, error) {
	var err error
	var res *Bottle
	if val, ok := raw.(map[string]interface{}); ok {
		res = new(Bottle)
		if v, ok := val["account"]; ok {
			var tmp29 *Account
			if val, ok := v.(map[string]interface{}); ok {
				tmp29 = new(Account)
				if v, ok := val["created_at"]; ok {
					var tmp30 string
					if val, ok := v.(string); ok {
						tmp30 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.CreatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp30 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp30); err2 != nil {
								err = goa.InvalidFormatError(`.Account.CreatedAt`, tmp30, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp29.CreatedAt = tmp30
				}
				if v, ok := val["created_by"]; ok {
					var tmp31 string
					if val, ok := v.(string); ok {
						tmp31 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.CreatedBy`, v, "string", err)
					}
					if err == nil {
						if tmp31 != "" {
							if err2 := goa.ValidateFormat(goa.FormatEmail, tmp31); err2 != nil {
								err = goa.InvalidFormatError(`.Account.CreatedBy`, tmp31, goa.FormatEmail, err2, err)
							}
						}
					}
					tmp29.CreatedBy = tmp31
				}
				if v, ok := val["href"]; ok {
					var tmp32 string
					if val, ok := v.(string); ok {
						tmp32 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.Href`, v, "string", err)
					}
					tmp29.Href = tmp32
				}
				if v, ok := val["id"]; ok {
					var tmp33 int
					if f, ok := v.(float64); ok {
						tmp33 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.ID`, v, "int", err)
					}
					tmp29.ID = tmp33
				}
				if v, ok := val["name"]; ok {
					var tmp34 string
					if val, ok := v.(string); ok {
						tmp34 = val
					} else {
						err = goa.InvalidAttributeTypeError(`.Account.Name`, v, "string", err)
					}
					tmp29.Name = tmp34
				}
			} else {
				err = goa.InvalidAttributeTypeError(`.Account`, v, "map[string]interface{}", err)
			}
			res.Account = tmp29
		}
		if v, ok := val["color"]; ok {
			var tmp35 string
			if val, ok := v.(string); ok {
				tmp35 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Color`, v, "string", err)
			}
			if err == nil {
				if tmp35 != "" {
					if !(tmp35 == "red" || tmp35 == "white" || tmp35 == "rose" || tmp35 == "yellow" || tmp35 == "sparkling") {
						err = goa.InvalidEnumValueError(`.Color`, tmp35, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
					}
				}
			}
			res.Color = tmp35
		}
		if v, ok := val["country"]; ok {
			var tmp36 string
			if val, ok := v.(string); ok {
				tmp36 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Country`, v, "string", err)
			}
			if err == nil {
				if len(tmp36) < 2 {
					err = goa.InvalidLengthError(`.Country`, tmp36, 2, true, err)
				}
			}
			res.Country = tmp36
		}
		if v, ok := val["created_at"]; ok {
			var tmp37 string
			if val, ok := v.(string); ok {
				tmp37 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp37 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp37); err2 != nil {
						err = goa.InvalidFormatError(`.CreatedAt`, tmp37, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.CreatedAt = tmp37
		}
		if v, ok := val["href"]; ok {
			var tmp38 string
			if val, ok := v.(string); ok {
				tmp38 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Href`, v, "string", err)
			}
			res.Href = tmp38
		}
		if v, ok := val["id"]; ok {
			var tmp39 int
			if f, ok := v.(float64); ok {
				tmp39 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.ID`, v, "int", err)
			}
			res.ID = tmp39
		}
		if v, ok := val["name"]; ok {
			var tmp40 string
			if val, ok := v.(string); ok {
				tmp40 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Name`, v, "string", err)
			}
			if err == nil {
				if len(tmp40) < 2 {
					err = goa.InvalidLengthError(`.Name`, tmp40, 2, true, err)
				}
			}
			res.Name = tmp40
		}
		if v, ok := val["rating"]; ok {
			var tmp41 int
			if f, ok := v.(float64); ok {
				tmp41 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.Rating`, v, "int", err)
			}
			if err == nil {
				if tmp41 < 1 {
					err = goa.InvalidRangeError(`.Rating`, tmp41, 1, true, err)
				}
				if tmp41 > 5 {
					err = goa.InvalidRangeError(`.Rating`, tmp41, 5, false, err)
				}
			}
			res.Rating = tmp41
		}
		if v, ok := val["region"]; ok {
			var tmp42 string
			if val, ok := v.(string); ok {
				tmp42 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Region`, v, "string", err)
			}
			res.Region = tmp42
		}
		if v, ok := val["review"]; ok {
			var tmp43 string
			if val, ok := v.(string); ok {
				tmp43 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Review`, v, "string", err)
			}
			if err == nil {
				if len(tmp43) < 10 {
					err = goa.InvalidLengthError(`.Review`, tmp43, 10, true, err)
				}
				if len(tmp43) > 300 {
					err = goa.InvalidLengthError(`.Review`, tmp43, 300, false, err)
				}
			}
			res.Review = tmp43
		}
		if v, ok := val["sweetness"]; ok {
			var tmp44 int
			if f, ok := v.(float64); ok {
				tmp44 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.Sweetness`, v, "int", err)
			}
			if err == nil {
				if tmp44 < 1 {
					err = goa.InvalidRangeError(`.Sweetness`, tmp44, 1, true, err)
				}
				if tmp44 > 5 {
					err = goa.InvalidRangeError(`.Sweetness`, tmp44, 5, false, err)
				}
			}
			res.Sweetness = tmp44
		}
		if v, ok := val["updated_at"]; ok {
			var tmp45 string
			if val, ok := v.(string); ok {
				tmp45 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.UpdatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp45 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp45); err2 != nil {
						err = goa.InvalidFormatError(`.UpdatedAt`, tmp45, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.UpdatedAt = tmp45
		}
		if v, ok := val["varietal"]; ok {
			var tmp46 string
			if val, ok := v.(string); ok {
				tmp46 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Varietal`, v, "string", err)
			}
			if err == nil {
				if len(tmp46) < 4 {
					err = goa.InvalidLengthError(`.Varietal`, tmp46, 4, true, err)
				}
			}
			res.Varietal = tmp46
		}
		if v, ok := val["vineyard"]; ok {
			var tmp47 string
			if val, ok := v.(string); ok {
				tmp47 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Vineyard`, v, "string", err)
			}
			if err == nil {
				if len(tmp47) < 2 {
					err = goa.InvalidLengthError(`.Vineyard`, tmp47, 2, true, err)
				}
			}
			res.Vineyard = tmp47
		}
		if v, ok := val["vintage"]; ok {
			var tmp48 int
			if f, ok := v.(float64); ok {
				tmp48 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`.Vintage`, v, "int", err)
			}
			if err == nil {
				if tmp48 < 1900 {
					err = goa.InvalidRangeError(`.Vintage`, tmp48, 1900, true, err)
				}
				if tmp48 > 2020 {
					err = goa.InvalidRangeError(`.Vintage`, tmp48, 2020, false, err)
				}
			}
			res.Vintage = tmp48
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "map[string]interface{}", err)
	}
	return res, err
}
Esempio n. 20
0
// MarshalBottleFull validates and renders an instance of Bottle into a interface{}
// using view "full".
func MarshalBottleFull(source *Bottle, inErr error) (target map[string]interface{}, err error) {
	err = inErr
	if source.Color != "" {
		if !(source.Color == "red" || source.Color == "white" || source.Color == "rose" || source.Color == "yellow" || source.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`.color`, source.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if len(source.Country) < 2 {
		err = goa.InvalidLengthError(`.country`, source.Country, len(source.Country), 2, true, err)
	}
	if source.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, source.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`.created_at`, source.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(source.Name) < 2 {
		err = goa.InvalidLengthError(`.name`, source.Name, len(source.Name), 2, true, err)
	}
	if source.Rating < 1 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 1, true, err)
	}
	if source.Rating > 5 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 5, false, err)
	}
	if len(source.Review) < 10 {
		err = goa.InvalidLengthError(`.review`, source.Review, len(source.Review), 10, true, err)
	}
	if len(source.Review) > 300 {
		err = goa.InvalidLengthError(`.review`, source.Review, len(source.Review), 300, false, err)
	}
	if source.Sweetness < 1 {
		err = goa.InvalidRangeError(`.sweetness`, source.Sweetness, 1, true, err)
	}
	if source.Sweetness > 5 {
		err = goa.InvalidRangeError(`.sweetness`, source.Sweetness, 5, false, err)
	}
	if source.UpdatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, source.UpdatedAt); err2 != nil {
			err = goa.InvalidFormatError(`.updated_at`, source.UpdatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(source.Varietal) < 4 {
		err = goa.InvalidLengthError(`.varietal`, source.Varietal, len(source.Varietal), 4, true, err)
	}
	if len(source.Vineyard) < 2 {
		err = goa.InvalidLengthError(`.vineyard`, source.Vineyard, len(source.Vineyard), 2, true, err)
	}
	if source.Vintage < 1900 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 1900, true, err)
	}
	if source.Vintage > 2020 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 2020, false, err)
	}
	tmp30 := map[string]interface{}{
		"color":      source.Color,
		"country":    source.Country,
		"created_at": source.CreatedAt,
		"href":       source.Href,
		"id":         source.ID,
		"name":       source.Name,
		"rating":     source.Rating,
		"region":     source.Region,
		"review":     source.Review,
		"sweetness":  source.Sweetness,
		"updated_at": source.UpdatedAt,
		"varietal":   source.Varietal,
		"vineyard":   source.Vineyard,
		"vintage":    source.Vintage,
	}
	if source.Account != nil {
		tmp30["account"], err = MarshalAccount(source.Account, err)
	}
	target = tmp30
	if err == nil {
		links := make(map[string]interface{})
		links["account"], err = MarshalAccountLink(source.Account, err)
		target["links"] = links
	}
	return
}
Esempio n. 21
0
// Dump produces raw data from an instance of Bottle running all the
// validations. See LoadBottle for the definition of raw data.
func (mt *Bottle) Dump(view BottleViewEnum) (map[string]interface{}, error) {
	var err error
	var res map[string]interface{}
	if view == BottleDefaultView {
		if len(mt.Name) < 2 {
			err = goa.InvalidLengthError(`default view.name`, mt.Name, 2, true, err)
		}
		if mt.Rating < 1 {
			err = goa.InvalidRangeError(`default view.rating`, mt.Rating, 1, true, err)
		}
		if mt.Rating > 5 {
			err = goa.InvalidRangeError(`default view.rating`, mt.Rating, 5, false, err)
		}
		if len(mt.Varietal) < 4 {
			err = goa.InvalidLengthError(`default view.varietal`, mt.Varietal, 4, true, err)
		}
		if len(mt.Vineyard) < 2 {
			err = goa.InvalidLengthError(`default view.vineyard`, mt.Vineyard, 2, true, err)
		}
		if mt.Vintage < 1900 {
			err = goa.InvalidRangeError(`default view.vintage`, mt.Vintage, 1900, true, err)
		}
		if mt.Vintage > 2020 {
			err = goa.InvalidRangeError(`default view.vintage`, mt.Vintage, 2020, false, err)
		}
		tmp50 := map[string]interface{}{
			"href":     mt.Href,
			"id":       mt.ID,
			"name":     mt.Name,
			"rating":   mt.Rating,
			"varietal": mt.Varietal,
			"vineyard": mt.Vineyard,
			"vintage":  mt.Vintage,
		}
		res = tmp50
		if err == nil {
			links := make(map[string]interface{})
			tmp49 := map[string]interface{}{
				"href": mt.Account.Href,
				"id":   mt.Account.ID,
				"name": mt.Account.Name,
			}
			links["account"] = tmp49
			res["links"] = links
		}
	}
	if view == BottleFullView {
		if mt.Color != "" {
			if !(mt.Color == "red" || mt.Color == "white" || mt.Color == "rose" || mt.Color == "yellow" || mt.Color == "sparkling") {
				err = goa.InvalidEnumValueError(`full view.color`, mt.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
			}
		}
		if len(mt.Country) < 2 {
			err = goa.InvalidLengthError(`full view.country`, mt.Country, 2, true, err)
		}
		if mt.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`full view.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(mt.Name) < 2 {
			err = goa.InvalidLengthError(`full view.name`, mt.Name, 2, true, err)
		}
		if mt.Rating < 1 {
			err = goa.InvalidRangeError(`full view.rating`, mt.Rating, 1, true, err)
		}
		if mt.Rating > 5 {
			err = goa.InvalidRangeError(`full view.rating`, mt.Rating, 5, false, err)
		}
		if len(mt.Review) < 10 {
			err = goa.InvalidLengthError(`full view.review`, mt.Review, 10, true, err)
		}
		if len(mt.Review) > 300 {
			err = goa.InvalidLengthError(`full view.review`, mt.Review, 300, false, err)
		}
		if mt.Sweetness < 1 {
			err = goa.InvalidRangeError(`full view.sweetness`, mt.Sweetness, 1, true, err)
		}
		if mt.Sweetness > 5 {
			err = goa.InvalidRangeError(`full view.sweetness`, mt.Sweetness, 5, false, err)
		}
		if mt.UpdatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.UpdatedAt); err2 != nil {
				err = goa.InvalidFormatError(`full view.updated_at`, mt.UpdatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(mt.Varietal) < 4 {
			err = goa.InvalidLengthError(`full view.varietal`, mt.Varietal, 4, true, err)
		}
		if len(mt.Vineyard) < 2 {
			err = goa.InvalidLengthError(`full view.vineyard`, mt.Vineyard, 2, true, err)
		}
		if mt.Vintage < 1900 {
			err = goa.InvalidRangeError(`full view.vintage`, mt.Vintage, 1900, true, err)
		}
		if mt.Vintage > 2020 {
			err = goa.InvalidRangeError(`full view.vintage`, mt.Vintage, 2020, false, err)
		}
		tmp52 := map[string]interface{}{
			"color":      mt.Color,
			"country":    mt.Country,
			"created_at": mt.CreatedAt,
			"href":       mt.Href,
			"id":         mt.ID,
			"name":       mt.Name,
			"rating":     mt.Rating,
			"region":     mt.Region,
			"review":     mt.Review,
			"sweetness":  mt.Sweetness,
			"updated_at": mt.UpdatedAt,
			"varietal":   mt.Varietal,
			"vineyard":   mt.Vineyard,
			"vintage":    mt.Vintage,
		}
		if mt.Account != nil {
			if mt.Account.CreatedAt != "" {
				if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.Account.CreatedAt); err2 != nil {
					err = goa.InvalidFormatError(`full view.Account.created_at`, mt.Account.CreatedAt, goa.FormatDateTime, err2, err)
				}
			}
			if mt.Account.CreatedBy != "" {
				if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Account.CreatedBy); err2 != nil {
					err = goa.InvalidFormatError(`full view.Account.created_by`, mt.Account.CreatedBy, goa.FormatEmail, err2, err)
				}
			}
			tmp53 := map[string]interface{}{
				"created_at": mt.Account.CreatedAt,
				"created_by": mt.Account.CreatedBy,
				"href":       mt.Account.Href,
				"id":         mt.Account.ID,
				"name":       mt.Account.Name,
			}
			tmp52["account"] = tmp53
		}
		res = tmp52
		if err == nil {
			links := make(map[string]interface{})
			tmp51 := map[string]interface{}{
				"href": mt.Account.Href,
				"id":   mt.Account.ID,
				"name": mt.Account.Name,
			}
			links["account"] = tmp51
			res["links"] = links
		}
	}
	if view == BottleTinyView {
		if len(mt.Name) < 2 {
			err = goa.InvalidLengthError(`tiny view.name`, mt.Name, 2, true, err)
		}
		if mt.Rating < 1 {
			err = goa.InvalidRangeError(`tiny view.rating`, mt.Rating, 1, true, err)
		}
		if mt.Rating > 5 {
			err = goa.InvalidRangeError(`tiny view.rating`, mt.Rating, 5, false, err)
		}
		tmp55 := map[string]interface{}{
			"href":   mt.Href,
			"id":     mt.ID,
			"name":   mt.Name,
			"rating": mt.Rating,
		}
		res = tmp55
		if err == nil {
			links := make(map[string]interface{})
			tmp54 := map[string]interface{}{
				"href": mt.Account.Href,
				"id":   mt.Account.ID,
				"name": mt.Account.Name,
			}
			links["account"] = tmp54
			res["links"] = links
		}
	}
	return res, err
}
Esempio n. 22
0
// LoadSeriesCollection loads raw data into an instance of SeriesCollection running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadSeriesCollection(raw interface{}) (SeriesCollection, error) {
	var err error
	var res SeriesCollection
	if val, ok := raw.([]interface{}); ok {
		res = make([]*Series, len(val))
		for i, v := range val {
			var tmp36 *Series
			if val, ok := v.(map[string]interface{}); ok {
				tmp36 = new(Series)
				if v, ok := val["account"]; ok {
					var tmp37 *Account
					if val, ok := v.(map[string]interface{}); ok {
						tmp37 = new(Account)
						if v, ok := val["created_at"]; ok {
							var tmp38 string
							if val, ok := v.(string); ok {
								tmp38 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.CreatedAt`, v, "string", err)
							}
							if err == nil {
								if tmp38 != "" {
									if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp38); err2 != nil {
										err = goa.InvalidFormatError(`[*].Account.CreatedAt`, tmp38, goa.FormatDateTime, err2, err)
									}
								}
							}
							tmp37.CreatedAt = tmp38
						}
						if v, ok := val["created_by"]; ok {
							var tmp39 string
							if val, ok := v.(string); ok {
								tmp39 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.CreatedBy`, v, "string", err)
							}
							if err == nil {
								if tmp39 != "" {
									if err2 := goa.ValidateFormat(goa.FormatEmail, tmp39); err2 != nil {
										err = goa.InvalidFormatError(`[*].Account.CreatedBy`, tmp39, goa.FormatEmail, err2, err)
									}
								}
							}
							tmp37.CreatedBy = tmp39
						}
						if v, ok := val["href"]; ok {
							var tmp40 string
							if val, ok := v.(string); ok {
								tmp40 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.Href`, v, "string", err)
							}
							tmp37.Href = tmp40
						}
						if v, ok := val["id"]; ok {
							var tmp41 int
							if f, ok := v.(float64); ok {
								tmp41 = int(f)
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.ID`, v, "int", err)
							}
							tmp37.ID = tmp41
						}
						if v, ok := val["name"]; ok {
							var tmp42 string
							if val, ok := v.(string); ok {
								tmp42 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.Name`, v, "string", err)
							}
							tmp37.Name = tmp42
						}
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Account`, v, "map[string]interface{}", err)
					}
					tmp36.Account = tmp37
				}
				if v, ok := val["created_at"]; ok {
					var tmp43 string
					if val, ok := v.(string); ok {
						tmp43 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].CreatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp43 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp43); err2 != nil {
								err = goa.InvalidFormatError(`[*].CreatedAt`, tmp43, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp36.CreatedAt = tmp43
				}
				if v, ok := val["href"]; ok {
					var tmp44 string
					if val, ok := v.(string); ok {
						tmp44 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Href`, v, "string", err)
					}
					tmp36.Href = tmp44
				}
				if v, ok := val["id"]; ok {
					var tmp45 int
					if f, ok := v.(float64); ok {
						tmp45 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].ID`, v, "int", err)
					}
					tmp36.ID = tmp45
				}
				if v, ok := val["name"]; ok {
					var tmp46 string
					if val, ok := v.(string); ok {
						tmp46 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Name`, v, "string", err)
					}
					if err == nil {
						if len(tmp46) < 2 {
							err = goa.InvalidLengthError(`[*].Name`, tmp46, 2, true, err)
						}
					}
					tmp36.Name = tmp46
				}
				if v, ok := val["updated_at"]; ok {
					var tmp47 string
					if val, ok := v.(string); ok {
						tmp47 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].UpdatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp47 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp47); err2 != nil {
								err = goa.InvalidFormatError(`[*].UpdatedAt`, tmp47, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp36.UpdatedAt = tmp47
				}
			} else {
				err = goa.InvalidAttributeTypeError(`[*]`, v, "map[string]interface{}", err)
			}
			res[i] = tmp36
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "[]interface{}", err)
	}
	return res, err
}
Esempio n. 23
0
// LoadBottleCollection loads raw data into an instance of BottleCollection running all the
// validations. Raw data is defined by data that the JSON unmarshaler would create when unmarshaling
// into a variable of type interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal for the
// complete list of supported data types.
func LoadBottleCollection(raw interface{}) (BottleCollection, error) {
	var err error
	var res BottleCollection
	if val, ok := raw.([]interface{}); ok {
		res = make([]*Bottle, len(val))
		for i, v := range val {
			var tmp56 *Bottle
			if val, ok := v.(map[string]interface{}); ok {
				tmp56 = new(Bottle)
				if v, ok := val["account"]; ok {
					var tmp57 *Account
					if val, ok := v.(map[string]interface{}); ok {
						tmp57 = new(Account)
						if v, ok := val["created_at"]; ok {
							var tmp58 string
							if val, ok := v.(string); ok {
								tmp58 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.CreatedAt`, v, "string", err)
							}
							if err == nil {
								if tmp58 != "" {
									if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp58); err2 != nil {
										err = goa.InvalidFormatError(`[*].Account.CreatedAt`, tmp58, goa.FormatDateTime, err2, err)
									}
								}
							}
							tmp57.CreatedAt = tmp58
						}
						if v, ok := val["created_by"]; ok {
							var tmp59 string
							if val, ok := v.(string); ok {
								tmp59 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.CreatedBy`, v, "string", err)
							}
							if err == nil {
								if tmp59 != "" {
									if err2 := goa.ValidateFormat(goa.FormatEmail, tmp59); err2 != nil {
										err = goa.InvalidFormatError(`[*].Account.CreatedBy`, tmp59, goa.FormatEmail, err2, err)
									}
								}
							}
							tmp57.CreatedBy = tmp59
						}
						if v, ok := val["href"]; ok {
							var tmp60 string
							if val, ok := v.(string); ok {
								tmp60 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.Href`, v, "string", err)
							}
							tmp57.Href = tmp60
						}
						if v, ok := val["id"]; ok {
							var tmp61 int
							if f, ok := v.(float64); ok {
								tmp61 = int(f)
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.ID`, v, "int", err)
							}
							tmp57.ID = tmp61
						}
						if v, ok := val["name"]; ok {
							var tmp62 string
							if val, ok := v.(string); ok {
								tmp62 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.Name`, v, "string", err)
							}
							tmp57.Name = tmp62
						}
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Account`, v, "map[string]interface{}", err)
					}
					tmp56.Account = tmp57
				}
				if v, ok := val["color"]; ok {
					var tmp63 string
					if val, ok := v.(string); ok {
						tmp63 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Color`, v, "string", err)
					}
					if err == nil {
						if tmp63 != "" {
							if !(tmp63 == "red" || tmp63 == "white" || tmp63 == "rose" || tmp63 == "yellow" || tmp63 == "sparkling") {
								err = goa.InvalidEnumValueError(`[*].Color`, tmp63, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
							}
						}
					}
					tmp56.Color = tmp63
				}
				if v, ok := val["country"]; ok {
					var tmp64 string
					if val, ok := v.(string); ok {
						tmp64 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Country`, v, "string", err)
					}
					if err == nil {
						if len(tmp64) < 2 {
							err = goa.InvalidLengthError(`[*].Country`, tmp64, 2, true, err)
						}
					}
					tmp56.Country = tmp64
				}
				if v, ok := val["created_at"]; ok {
					var tmp65 string
					if val, ok := v.(string); ok {
						tmp65 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].CreatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp65 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp65); err2 != nil {
								err = goa.InvalidFormatError(`[*].CreatedAt`, tmp65, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp56.CreatedAt = tmp65
				}
				if v, ok := val["href"]; ok {
					var tmp66 string
					if val, ok := v.(string); ok {
						tmp66 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Href`, v, "string", err)
					}
					tmp56.Href = tmp66
				}
				if v, ok := val["id"]; ok {
					var tmp67 int
					if f, ok := v.(float64); ok {
						tmp67 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].ID`, v, "int", err)
					}
					tmp56.ID = tmp67
				}
				if v, ok := val["name"]; ok {
					var tmp68 string
					if val, ok := v.(string); ok {
						tmp68 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Name`, v, "string", err)
					}
					if err == nil {
						if len(tmp68) < 2 {
							err = goa.InvalidLengthError(`[*].Name`, tmp68, 2, true, err)
						}
					}
					tmp56.Name = tmp68
				}
				if v, ok := val["rating"]; ok {
					var tmp69 int
					if f, ok := v.(float64); ok {
						tmp69 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Rating`, v, "int", err)
					}
					if err == nil {
						if tmp69 < 1 {
							err = goa.InvalidRangeError(`[*].Rating`, tmp69, 1, true, err)
						}
						if tmp69 > 5 {
							err = goa.InvalidRangeError(`[*].Rating`, tmp69, 5, false, err)
						}
					}
					tmp56.Rating = tmp69
				}
				if v, ok := val["region"]; ok {
					var tmp70 string
					if val, ok := v.(string); ok {
						tmp70 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Region`, v, "string", err)
					}
					tmp56.Region = tmp70
				}
				if v, ok := val["review"]; ok {
					var tmp71 string
					if val, ok := v.(string); ok {
						tmp71 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Review`, v, "string", err)
					}
					if err == nil {
						if len(tmp71) < 10 {
							err = goa.InvalidLengthError(`[*].Review`, tmp71, 10, true, err)
						}
						if len(tmp71) > 300 {
							err = goa.InvalidLengthError(`[*].Review`, tmp71, 300, false, err)
						}
					}
					tmp56.Review = tmp71
				}
				if v, ok := val["sweetness"]; ok {
					var tmp72 int
					if f, ok := v.(float64); ok {
						tmp72 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Sweetness`, v, "int", err)
					}
					if err == nil {
						if tmp72 < 1 {
							err = goa.InvalidRangeError(`[*].Sweetness`, tmp72, 1, true, err)
						}
						if tmp72 > 5 {
							err = goa.InvalidRangeError(`[*].Sweetness`, tmp72, 5, false, err)
						}
					}
					tmp56.Sweetness = tmp72
				}
				if v, ok := val["updated_at"]; ok {
					var tmp73 string
					if val, ok := v.(string); ok {
						tmp73 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].UpdatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp73 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp73); err2 != nil {
								err = goa.InvalidFormatError(`[*].UpdatedAt`, tmp73, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp56.UpdatedAt = tmp73
				}
				if v, ok := val["varietal"]; ok {
					var tmp74 string
					if val, ok := v.(string); ok {
						tmp74 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Varietal`, v, "string", err)
					}
					if err == nil {
						if len(tmp74) < 4 {
							err = goa.InvalidLengthError(`[*].Varietal`, tmp74, 4, true, err)
						}
					}
					tmp56.Varietal = tmp74
				}
				if v, ok := val["vineyard"]; ok {
					var tmp75 string
					if val, ok := v.(string); ok {
						tmp75 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Vineyard`, v, "string", err)
					}
					if err == nil {
						if len(tmp75) < 2 {
							err = goa.InvalidLengthError(`[*].Vineyard`, tmp75, 2, true, err)
						}
					}
					tmp56.Vineyard = tmp75
				}
				if v, ok := val["vintage"]; ok {
					var tmp76 int
					if f, ok := v.(float64); ok {
						tmp76 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Vintage`, v, "int", err)
					}
					if err == nil {
						if tmp76 < 1900 {
							err = goa.InvalidRangeError(`[*].Vintage`, tmp76, 1900, true, err)
						}
						if tmp76 > 2020 {
							err = goa.InvalidRangeError(`[*].Vintage`, tmp76, 2020, false, err)
						}
					}
					tmp56.Vintage = tmp76
				}
			} else {
				err = goa.InvalidAttributeTypeError(`[*]`, v, "map[string]interface{}", err)
			}
			res[i] = tmp56
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "[]interface{}", err)
	}
	return res, err
}
Esempio n. 24
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/raphael/goa"
)

var _ = Describe("ValidateFormat", func() {
	var f goa.Format
	var val string
	var valErr error

	BeforeEach(func() {
		val = ""
	})

	JustBeforeEach(func() {
		valErr = goa.ValidateFormat(f, val)
	})

	Context("DateTime", func() {
		BeforeEach(func() {
			f = goa.FormatDateTime
		})

		Context("with an invalid value", func() {
			BeforeEach(func() {
				val = "201510-26T08:31:23Z"
			})

			It("does not validates", func() {
				Ω(valErr).Should(HaveOccurred())
			})