Example #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
}
Example #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
}
Example #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
}
Example #4
0
// Validate runs the validation rules defined in the design.
func (payload *CreateAccountPayload) Validate() (err error) {
	if payload.Name == "" {
		err = goa.MissingAttributeError(`raw`, "name", err)
	}

	return
}
// 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
}
Example #6
0
		Ω(valErr).ShouldNot(BeNil())
		Ω(valErr).Should(BeAssignableToTypeOf(&goa.Error{}))
		err := valErr.(*goa.Error)
		Ω(err.Detail).Should(ContainSubstring(ctx))
		Ω(err.Detail).Should(ContainSubstring("%d", val))
		Ω(err.Detail).Should(ContainSubstring(expected))
	})
})

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

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

	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(name))
	})
})

var _ = Describe("MissingHeaderError", func() {
	var valErr error
	name := "param"