Example #1
0
// NewRateBottlePayload instantiates a RateBottlePayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewRateBottlePayload(raw interface{}) (*RateBottlePayload, error) {
	var err error
	var p *RateBottlePayload
	if val, ok := raw.(map[string]interface{}); ok {
		p = new(RateBottlePayload)
		if v, ok := val["rating"]; ok {
			var tmp12 int
			if f, ok := v.(float64); ok {
				tmp12 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Rating`, v, "int", err)
			}
			if err == nil {
				if tmp12 < 1 {
					err = goa.InvalidRangeError(`payload.Rating`, tmp12, 1, true, err)
				}
				if tmp12 > 5 {
					err = goa.InvalidRangeError(`payload.Rating`, tmp12, 5, false, err)
				}
			}
			p.Rating = tmp12
		} else {
			err = goa.MissingAttributeError(`payload`, "rating", err)
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
	}
	return p, err
}
Example #2
0
// UnmarshalRateBottlePayload unmarshals and validates a raw interface{} into an instance of RateBottlePayload
func UnmarshalRateBottlePayload(source interface{}, inErr error) (target *RateBottlePayload, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(RateBottlePayload)
		if v, ok := val["rating"]; ok {
			var tmp12 int
			if f, ok := v.(float64); ok {
				tmp12 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Rating`, v, "int", err)
			}
			if err == nil {
				if tmp12 < 1 {
					err = goa.InvalidRangeError(`payload.Rating`, tmp12, 1, true, err)
				}
				if tmp12 > 5 {
					err = goa.InvalidRangeError(`payload.Rating`, tmp12, 5, false, err)
				}
			}
			target.Rating = tmp12
		} else {
			err = goa.MissingAttributeError(`payload`, "rating", err)
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, source, "dictionary", err)
	}
	return
}
Example #3
0
// NewCreateSeriesPayload instantiates a CreateSeriesPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewCreateSeriesPayload(raw interface{}) (*CreateSeriesPayload, error) {
	var err error
	var p *CreateSeriesPayload
	if val, ok := raw.(map[string]interface{}); ok {
		p = new(CreateSeriesPayload)
		if v, ok := val["name"]; ok {
			var tmp3 string
			if val, ok := v.(string); ok {
				tmp3 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
			}
			if err == nil {
				if len(tmp3) < 2 {
					err = goa.InvalidLengthError(`payload.Name`, tmp3, 2, true, err)
				}
			}
			p.Name = tmp3
		} else {
			err = goa.MissingAttributeError(`payload`, "name", err)
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
	}
	return p, err
}
Example #4
0
// NewCreateUserPayload instantiates a CreateUserPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewCreateUserPayload(raw interface{}) (*CreateUserPayload, error) {
	var err error
	var p *CreateUserPayload
	if val, ok := raw.(map[string]interface{}); ok {
		p = new(CreateUserPayload)
		if v, ok := val["email"]; ok {
			var tmp5 string
			if val, ok := v.(string); ok {
				tmp5 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Email`, v, "string", err)
			}
			if err == nil {
				if len(tmp5) < 2 {
					err = goa.InvalidLengthError(`payload.Email`, tmp5, 2, true, err)
				}
			}
			p.Email = tmp5
		}
		if v, ok := val["first_name"]; ok {
			var tmp6 string
			if val, ok := v.(string); ok {
				tmp6 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.FirstName`, v, "string", err)
			}
			if err == nil {
				if len(tmp6) < 2 {
					err = goa.InvalidLengthError(`payload.FirstName`, tmp6, 2, true, err)
				}
			}
			p.FirstName = tmp6
		} else {
			err = goa.MissingAttributeError(`payload`, "first_name", err)
		}
		if v, ok := val["last_name"]; ok {
			var tmp7 string
			if val, ok := v.(string); ok {
				tmp7 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.LastName`, v, "string", err)
			}
			if err == nil {
				if len(tmp7) < 2 {
					err = goa.InvalidLengthError(`payload.LastName`, tmp7, 2, true, err)
				}
			}
			p.LastName = tmp7
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
	}
	return p, err
}
Example #5
0
// UnmarshalCreateAccountPayload unmarshals and validates a raw interface{} into an instance of CreateAccountPayload
func UnmarshalCreateAccountPayload(source interface{}, inErr error) (target *CreateAccountPayload, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(CreateAccountPayload)
		if v, ok := val["name"]; ok {
			var tmp1 string
			if val, ok := v.(string); ok {
				tmp1 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
			}
			target.Name = tmp1
		} else {
			err = goa.MissingAttributeError(`payload`, "name", err)
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, source, "dictionary", err)
	}
	return
}
Example #6
0
// NewCreateAccountPayload instantiates a CreateAccountPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewCreateAccountPayload(raw interface{}) (*CreateAccountPayload, error) {
	var err error
	var p *CreateAccountPayload
	if val, ok := raw.(map[string]interface{}); ok {
		p = new(CreateAccountPayload)
		if v, ok := val["name"]; ok {
			var tmp1 string
			if val, ok := v.(string); ok {
				tmp1 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
			}
			p.Name = tmp1
		} else {
			err = goa.MissingAttributeError(`payload`, "name", err)
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
	}
	return p, err
}
Example #7
0
			Ω(tErr.Mesg).Should(ContainSubstring(expected))
		})
	})
})

var _ = Describe("MissingAttributeError", func() {
	var valErr, err error
	ctx := "ctx"
	name := "param"

	BeforeEach(func() {
		err = nil
	})

	JustBeforeEach(func() {
		valErr = goa.MissingAttributeError(ctx, name, err)
	})

	It("creates a multi error", func() {
		Ω(valErr).ShouldNot(BeNil())
		Ω(valErr).Should(BeAssignableToTypeOf(goa.MultiError{}))
		mErr := valErr.(goa.MultiError)
		Ω(mErr).Should(HaveLen(1))
		Ω(mErr[0]).Should(BeAssignableToTypeOf(&goa.TypedError{}))
		tErr := mErr[0].(*goa.TypedError)
		Ω(tErr.ID).Should(Equal(goa.ErrorID((goa.ErrMissingAttribute))))
		Ω(tErr.Mesg).Should(ContainSubstring(ctx))
		Ω(tErr.Mesg).Should(ContainSubstring(name))
	})

	Context("with a pre-existing error", func() {
Example #8
0
// UnmarshalCreateBottlePayload unmarshals and validates a raw interface{} into an instance of CreateBottlePayload
func UnmarshalCreateBottlePayload(source interface{}, inErr error) (target *CreateBottlePayload, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(CreateBottlePayload)
		if v, ok := val["color"]; ok {
			var tmp3 string
			if val, ok := v.(string); ok {
				tmp3 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Color`, v, "string", err)
			}
			if err == nil {
				if tmp3 != "" {
					if !(tmp3 == "red" || tmp3 == "white" || tmp3 == "rose" || tmp3 == "yellow" || tmp3 == "sparkling") {
						err = goa.InvalidEnumValueError(`payload.Color`, tmp3, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
					}
				}
			}
			target.Color = tmp3
		} else {
			err = goa.MissingAttributeError(`payload`, "color", err)
		}
		if v, ok := val["country"]; ok {
			var tmp4 string
			if val, ok := v.(string); ok {
				tmp4 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Country`, v, "string", err)
			}
			if err == nil {
				if len(tmp4) < 2 {
					err = goa.InvalidLengthError(`payload.Country`, tmp4, len(tmp4), 2, true, err)
				}
			}
			target.Country = tmp4
		}
		if v, ok := val["name"]; ok {
			var tmp5 string
			if val, ok := v.(string); ok {
				tmp5 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
			}
			if err == nil {
				if len(tmp5) < 2 {
					err = goa.InvalidLengthError(`payload.Name`, tmp5, len(tmp5), 2, true, err)
				}
			}
			target.Name = tmp5
		} else {
			err = goa.MissingAttributeError(`payload`, "name", err)
		}
		if v, ok := val["region"]; ok {
			var tmp6 string
			if val, ok := v.(string); ok {
				tmp6 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Region`, v, "string", err)
			}
			target.Region = tmp6
		}
		if v, ok := val["review"]; ok {
			var tmp7 string
			if val, ok := v.(string); ok {
				tmp7 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Review`, v, "string", err)
			}
			if err == nil {
				if len(tmp7) < 10 {
					err = goa.InvalidLengthError(`payload.Review`, tmp7, len(tmp7), 10, true, err)
				}
				if len(tmp7) > 300 {
					err = goa.InvalidLengthError(`payload.Review`, tmp7, len(tmp7), 300, false, err)
				}
			}
			target.Review = tmp7
		}
		if v, ok := val["sweetness"]; ok {
			var tmp8 int
			if f, ok := v.(float64); ok {
				tmp8 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Sweetness`, v, "int", err)
			}
			if err == nil {
				if tmp8 < 1 {
					err = goa.InvalidRangeError(`payload.Sweetness`, tmp8, 1, true, err)
				}
				if tmp8 > 5 {
					err = goa.InvalidRangeError(`payload.Sweetness`, tmp8, 5, false, err)
				}
			}
			target.Sweetness = tmp8
		}
		if v, ok := val["varietal"]; ok {
			var tmp9 string
			if val, ok := v.(string); ok {
				tmp9 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Varietal`, v, "string", err)
			}
			if err == nil {
				if len(tmp9) < 4 {
					err = goa.InvalidLengthError(`payload.Varietal`, tmp9, len(tmp9), 4, true, err)
				}
			}
			target.Varietal = tmp9
		} else {
			err = goa.MissingAttributeError(`payload`, "varietal", err)
		}
		if v, ok := val["vineyard"]; ok {
			var tmp10 string
			if val, ok := v.(string); ok {
				tmp10 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Vineyard`, v, "string", err)
			}
			if err == nil {
				if len(tmp10) < 2 {
					err = goa.InvalidLengthError(`payload.Vineyard`, tmp10, len(tmp10), 2, true, err)
				}
			}
			target.Vineyard = tmp10
		} else {
			err = goa.MissingAttributeError(`payload`, "vineyard", err)
		}
		if v, ok := val["vintage"]; ok {
			var tmp11 int
			if f, ok := v.(float64); ok {
				tmp11 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Vintage`, v, "int", err)
			}
			if err == nil {
				if tmp11 < 1900 {
					err = goa.InvalidRangeError(`payload.Vintage`, tmp11, 1900, true, err)
				}
				if tmp11 > 2020 {
					err = goa.InvalidRangeError(`payload.Vintage`, tmp11, 2020, false, err)
				}
			}
			target.Vintage = tmp11
		} else {
			err = goa.MissingAttributeError(`payload`, "vintage", err)
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, source, "dictionary", err)
	}
	return
}