// 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 }
// 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 }
// 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 }
// NewShowBottleContext parses the incoming request URL and body, performs validations and creates the // context used by the bottle controller show action. func NewShowBottleContext(ctx context.Context, service *goa.Service) (*ShowBottleContext, error) { var err error resp := goa.ContextResponse(ctx) resp.Service = service req := goa.ContextRequest(ctx) rctx := ShowBottleContext{Context: ctx, ResponseData: resp, RequestData: req} paramID := req.Params["id"] if len(paramID) > 0 { rawID := paramID[0] if id, err2 := strconv.Atoi(rawID); err2 == nil { rctx.ID = id } else { err = goa.MergeErrors(err, goa.InvalidParamTypeError("id", rawID, "integer")) } } return &rctx, err }
}) }) }) var _ = Describe("Merge", func() { var err, err2 error var mErr *goa.Error BeforeEach(func() { err = nil err2 = nil mErr = nil }) JustBeforeEach(func() { e := goa.MergeErrors(err, err2) if e != nil { mErr = e.(*goa.Error) } }) Context("with two nil errors", func() { It("returns a nil error", func() { Ω(mErr).Should(BeNil()) }) }) Context("with a nil argument", func() { const code = "foo" BeforeEach(func() {