Exemplo n.º 1
0
// Validate runs the validation rules defined in the design.
func (payload *createBottlePayload) Validate() (err error) {
	if payload.Name == nil {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`payload`, "name"))
	}
	if payload.Vintage == nil {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`payload`, "vintage"))
	}
	if payload.Rating == nil {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`payload`, "rating"))
	}

	if payload.Name != nil {
		if len(*payload.Name) < 1 {
			err = goa.MergeErrors(err, goa.InvalidLengthError(`payload.name`, *payload.Name, len(*payload.Name), 1, true))
		}
	}
	if payload.Rating != nil {
		if *payload.Rating < 1 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`payload.rating`, *payload.Rating, 1, true))
		}
	}
	if payload.Rating != nil {
		if *payload.Rating > 5 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`payload.rating`, *payload.Rating, 5, false))
		}
	}
	if payload.Vintage != nil {
		if *payload.Vintage < 1900 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`payload.vintage`, *payload.Vintage, 1900, true))
		}
	}
	return
}
Exemplo n.º 2
0
// Validate validates the bottlePayload type instance.
func (ut *bottlePayload) Validate() (err error) {
	if ut.Name == nil {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "name"))
	}
	if ut.Vintage == nil {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "vintage"))
	}
	if ut.Rating == nil {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "rating"))
	}

	if ut.Name != nil {
		if len(*ut.Name) < 1 {
			err = goa.MergeErrors(err, goa.InvalidLengthError(`response.name`, *ut.Name, len(*ut.Name), 1, true))
		}
	}
	if ut.Rating != nil {
		if *ut.Rating < 1 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`response.rating`, *ut.Rating, 1, true))
		}
	}
	if ut.Rating != nil {
		if *ut.Rating > 5 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`response.rating`, *ut.Rating, 5, false))
		}
	}
	if ut.Vintage != nil {
		if *ut.Vintage < 1900 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`response.vintage`, *ut.Vintage, 1900, true))
		}
	}
	return
}
Exemplo n.º 3
0
// Validate runs the validation rules defined in the design.
func (payload *CreateBottlePayload) Validate() (err error) {
	if payload.Name == "" {
		err = goa.MissingAttributeError(`raw`, "name", err)
	}
	if payload.Vineyard == "" {
		err = goa.MissingAttributeError(`raw`, "vineyard", err)
	}
	if payload.Varietal == "" {
		err = goa.MissingAttributeError(`raw`, "varietal", err)
	}

	if payload.Color == "" {
		err = goa.MissingAttributeError(`raw`, "color", err)
	}

	if !(payload.Color == "red" || payload.Color == "white" || payload.Color == "rose" || payload.Color == "yellow" || payload.Color == "sparkling") {
		err = goa.InvalidEnumValueError(`raw.color`, payload.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
	}
	if payload.Country != nil {
		if len(*payload.Country) < 2 {
			err = goa.InvalidLengthError(`raw.country`, *payload.Country, len(*payload.Country), 2, true, err)
		}
	}
	if len(payload.Name) < 2 {
		err = goa.InvalidLengthError(`raw.name`, payload.Name, len(payload.Name), 2, true, err)
	}
	if payload.Review != nil {
		if len(*payload.Review) < 3 {
			err = goa.InvalidLengthError(`raw.review`, *payload.Review, len(*payload.Review), 3, true, err)
		}
	}
	if payload.Review != nil {
		if len(*payload.Review) > 300 {
			err = goa.InvalidLengthError(`raw.review`, *payload.Review, len(*payload.Review), 300, false, err)
		}
	}
	if payload.Sweetness != nil {
		if *payload.Sweetness < 1 {
			err = goa.InvalidRangeError(`raw.sweetness`, *payload.Sweetness, 1, true, err)
		}
	}
	if payload.Sweetness != nil {
		if *payload.Sweetness > 5 {
			err = goa.InvalidRangeError(`raw.sweetness`, *payload.Sweetness, 5, false, err)
		}
	}
	if len(payload.Varietal) < 4 {
		err = goa.InvalidLengthError(`raw.varietal`, payload.Varietal, len(payload.Varietal), 4, true, err)
	}
	if len(payload.Vineyard) < 2 {
		err = goa.InvalidLengthError(`raw.vineyard`, payload.Vineyard, len(payload.Vineyard), 2, true, err)
	}
	if payload.Vintage < 1900 {
		err = goa.InvalidRangeError(`raw.vintage`, payload.Vintage, 1900, true, err)
	}
	if payload.Vintage > 2020 {
		err = goa.InvalidRangeError(`raw.vintage`, payload.Vintage, 2020, false, err)
	}
	return
}
Exemplo n.º 4
0
// Validate validates the type instance.
func (ut *BottlePayload) Validate() (err error) {
	if ut.Color != nil {
		if !(*ut.Color == "red" || *ut.Color == "white" || *ut.Color == "rose" || *ut.Color == "yellow" || *ut.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`response.color`, *ut.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if ut.Country != nil {
		if len(*ut.Country) < 2 {
			err = goa.InvalidLengthError(`response.country`, *ut.Country, len(*ut.Country), 2, true, err)
		}
	}
	if ut.Name != nil {
		if len(*ut.Name) < 2 {
			err = goa.InvalidLengthError(`response.name`, *ut.Name, len(*ut.Name), 2, true, err)
		}
	}
	if ut.Review != nil {
		if len(*ut.Review) < 3 {
			err = goa.InvalidLengthError(`response.review`, *ut.Review, len(*ut.Review), 3, true, err)
		}
	}
	if ut.Review != nil {
		if len(*ut.Review) > 300 {
			err = goa.InvalidLengthError(`response.review`, *ut.Review, len(*ut.Review), 300, false, err)
		}
	}
	if ut.Sweetness != nil {
		if *ut.Sweetness < 1 {
			err = goa.InvalidRangeError(`response.sweetness`, *ut.Sweetness, 1, true, err)
		}
	}
	if ut.Sweetness != nil {
		if *ut.Sweetness > 5 {
			err = goa.InvalidRangeError(`response.sweetness`, *ut.Sweetness, 5, false, err)
		}
	}
	if ut.Varietal != nil {
		if len(*ut.Varietal) < 4 {
			err = goa.InvalidLengthError(`response.varietal`, *ut.Varietal, len(*ut.Varietal), 4, true, err)
		}
	}
	if ut.Vineyard != nil {
		if len(*ut.Vineyard) < 2 {
			err = goa.InvalidLengthError(`response.vineyard`, *ut.Vineyard, len(*ut.Vineyard), 2, true, err)
		}
	}
	if ut.Vintage != nil {
		if *ut.Vintage < 1900 {
			err = goa.InvalidRangeError(`response.vintage`, *ut.Vintage, 1900, true, err)
		}
	}
	if ut.Vintage != nil {
		if *ut.Vintage > 2020 {
			err = goa.InvalidRangeError(`response.vintage`, *ut.Vintage, 2020, false, err)
		}
	}
	return
}
Exemplo n.º 5
0
// Validate validates the Bottle media type instance.
func (mt *Bottle) Validate() (err error) {
	if mt.Name == "" {
		err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "name"))
	}

	if len(mt.Name) < 1 {
		err = goa.MergeErrors(err, goa.InvalidLengthError(`response.name`, mt.Name, len(mt.Name), 1, true))
	}
	if mt.Rating < 1 {
		err = goa.MergeErrors(err, goa.InvalidRangeError(`response.rating`, mt.Rating, 1, true))
	}
	if mt.Rating > 5 {
		err = goa.MergeErrors(err, goa.InvalidRangeError(`response.rating`, mt.Rating, 5, false))
	}
	if mt.Vintage < 1900 {
		err = goa.MergeErrors(err, goa.InvalidRangeError(`response.vintage`, mt.Vintage, 1900, true))
	}
	return
}
Exemplo n.º 6
0
		Ω(err.Detail).Should(ContainSubstring(target))
	})
})

var _ = Describe("InvalidLengthError", func() {
	const ctx = "ctx"
	const value = 42
	const min = true

	var target interface{}
	var ln int

	var valErr error

	JustBeforeEach(func() {
		valErr = goa.InvalidLengthError(ctx, target, ln, value, min)
	})

	Context("on strings", func() {
		BeforeEach(func() {
			target = "target"
			ln = len("target")
		})

		It("creates a http error", func() {
			Ω(valErr).ShouldNot(BeNil())
			Ω(valErr).Should(BeAssignableToTypeOf(&goa.Error{}))
			err := valErr.(*goa.Error)
			Ω(err.Detail).Should(ContainSubstring(ctx))
			Ω(err.Detail).Should(ContainSubstring("greater or equal"))
			Ω(err.Detail).Should(ContainSubstring(fmt.Sprintf("%#v", value)))