github.com/circl-dev/go-swagger@v0.31.0/examples/composed-auth/restapi/operations/add_order_parameters.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package operations 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "context" 10 "io" 11 "net/http" 12 13 "github.com/go-openapi/errors" 14 "github.com/circl-dev/runtime" 15 "github.com/circl-dev/runtime/middleware" 16 "github.com/circl-dev/validate" 17 18 "github.com/circl-dev/go-swagger/examples/composed-auth/models" 19 ) 20 21 // NewAddOrderParams creates a new AddOrderParams object 22 // 23 // There are no default values defined in the spec. 24 func NewAddOrderParams() AddOrderParams { 25 26 return AddOrderParams{} 27 } 28 29 // AddOrderParams contains all the bound params for the add order operation 30 // typically these are obtained from a http.Request 31 // 32 // swagger:parameters AddOrder 33 type AddOrderParams struct { 34 35 // HTTP Request Object 36 HTTPRequest *http.Request `json:"-"` 37 38 /* 39 Required: true 40 In: body 41 */ 42 Order *models.Order 43 } 44 45 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 46 // for simple values it will use straight method calls. 47 // 48 // To ensure default values, the struct must have been initialized with NewAddOrderParams() beforehand. 49 func (o *AddOrderParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 50 var res []error 51 52 o.HTTPRequest = r 53 54 if runtime.HasBody(r) { 55 defer r.Body.Close() 56 var body models.Order 57 if err := route.Consumer.Consume(r.Body, &body); err != nil { 58 if err == io.EOF { 59 res = append(res, errors.Required("order", "body", "")) 60 } else { 61 res = append(res, errors.NewParseError("order", "body", "", err)) 62 } 63 } else { 64 // validate body object 65 if err := body.Validate(route.Formats); err != nil { 66 res = append(res, err) 67 } 68 69 ctx := validate.WithOperationRequest(context.Background()) 70 if err := body.ContextValidate(ctx, route.Formats); err != nil { 71 res = append(res, err) 72 } 73 74 if len(res) == 0 { 75 o.Order = &body 76 } 77 } 78 } else { 79 res = append(res, errors.Required("order", "body", "")) 80 } 81 if len(res) > 0 { 82 return errors.CompositeValidationError(res...) 83 } 84 return nil 85 }