// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *UploadFileParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error if err := r.ParseMultipartForm(32 << 20); err != nil { return err } fds := httpkit.Values(r.Form) fdAdditionalMetadata, fdhkAdditionalMetadata, _ := fds.GetOK("additionalMetadata") if err := o.bindAdditionalMetadata(fdAdditionalMetadata, fdhkAdditionalMetadata, route.Formats); err != nil { res = append(res, err) } file, fileHeader, err := r.FormFile("file") if err != nil { res = append(res, errors.New(400, "reading file %q failed: %v", "file", err)) } else { o.File = httpkit.File{Data: file, Header: fileHeader} } rPetID, rhkPetID, _ := route.Params.GetOK("petId") if err := o.bindPetID(rPetID, rhkPetID, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *ListTasksParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error qs := httpkit.Values(r.URL.Query()) qPageSize, qhkPageSize, _ := qs.GetOK("pageSize") if err := o.bindPageSize(qPageSize, qhkPageSize, route.Formats); err != nil { res = append(res, err) } qSinceID, qhkSinceID, _ := qs.GetOK("sinceId") if err := o.bindSinceID(qSinceID, qhkSinceID, route.Formats); err != nil { res = append(res, err) } qStatus, qhkStatus, _ := qs.GetOK("status") if err := o.bindStatus(qStatus, qhkStatus, route.Formats); err != nil { res = append(res, err) } qTags, qhkTags, _ := qs.GetOK("tags") if err := o.bindTags(qTags, qhkTags, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *UpdatePetWithFormParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error if err := r.ParseMultipartForm(32 << 20); err != nil { return err } fds := httpkit.Values(r.Form) fdName, fdhkName, _ := fds.GetOK("name") if err := o.bindName(fdName, fdhkName, route.Formats); err != nil { res = append(res, err) } rPetID, rhkPetID, _ := route.Params.GetOK("petId") if err := o.bindPetID(rPetID, rhkPetID, route.Formats); err != nil { res = append(res, err) } fdStatus, fdhkStatus, _ := fds.GetOK("status") if err := o.bindStatus(fdStatus, fdhkStatus, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *FindParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error if err := r.ParseMultipartForm(32 << 20); err != nil { if err != http.ErrNotMultipart { return err } else if err := r.ParseForm(); err != nil { return err } } fds := httpkit.Values(r.Form) if err := o.bindXRateLimit(r.Header["X-Rate-Limit"], true, route.Formats); err != nil { res = append(res, err) } fdLimit, fdhkLimit, _ := fds.GetOK("limit") if err := o.bindLimit(fdLimit, fdhkLimit, route.Formats); err != nil { res = append(res, err) } fdTags, fdhkTags, _ := fds.GetOK("tags") if err := o.bindTags(fdTags, fdhkTags, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *UploadTaskFileParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error if err := r.ParseMultipartForm(32 << 20); err != nil { if err != http.ErrNotMultipart { return err } else if err := r.ParseForm(); err != nil { return err } } fds := httpkit.Values(r.Form) fdDescription, fdhkDescription, _ := fds.GetOK("description") if err := o.bindDescription(fdDescription, fdhkDescription, route.Formats); err != nil { res = append(res, err) } file, fileHeader, err := r.FormFile("file") if err != nil { res = append(res, errors.New(400, "reading file %q failed: %v", "file", err)) } else { o.File = httpkit.File{Data: file, Header: fileHeader} } rID, rhkID, _ := route.Params.GetOK("id") if err := o.bindID(rID, rhkID, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
func testCollectionFormat(t *testing.T, param *spec.Parameter, valid bool) { binder := &untypedParamBinder{ parameter: param, } _, _, _, err := binder.readValue(httpkit.Values(nil), reflect.ValueOf(nil)) if valid { assert.NoError(t, err) } else { assert.Error(t, err) assert.Equal(t, errors.InvalidCollectionFormat(param.Name, param.In, param.CollectionFormat), err) } }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *FindPetsByTagsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error qs := httpkit.Values(r.URL.Query()) qTags, qhkTags, _ := qs.GetOK("tags") if err := o.bindTags(qTags, qhkTags, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *ListEventsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error qs := httpkit.Values(r.URL.Query()) qLimit, qhkLimit, _ := qs.GetOK("limit") if err := o.bindLimit(qLimit, qhkLimit, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *LoginUserParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error qs := httpkit.Values(r.URL.Query()) qPassword, qhkPassword, _ := qs.GetOK("password") if err := o.bindPassword(qPassword, qhkPassword, route.Formats); err != nil { res = append(res, err) } qUsername, qhkUsername, _ := qs.GetOK("username") if err := o.bindUsername(qUsername, qhkUsername, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls func (o *GetTaskCommentsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error qs := httpkit.Values(r.URL.Query()) rID, rhkID, _ := route.Params.GetOK("id") if err := o.bindID(rID, rhkID, route.Formats); err != nil { res = append(res, err) } qPageSize, qhkPageSize, _ := qs.GetOK("pageSize") if err := o.bindPageSize(qPageSize, qhkPageSize, route.Formats); err != nil { res = append(res, err) } qSince, qhkSince, _ := qs.GetOK("since") if err := o.bindSince(qSince, qhkSince, route.Formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
func (p *untypedParamBinder) Bind(request *http.Request, routeParams RouteParams, consumer httpkit.Consumer, target reflect.Value) error { // fmt.Println("binding", p.name, "as", p.Type()) switch p.parameter.In { case "query": data, custom, hasKey, err := p.readValue(httpkit.Values(request.URL.Query()), target) if err != nil { return err } if custom { return nil } return p.bindValue(data, hasKey, target) case "header": data, custom, hasKey, err := p.readValue(httpkit.Values(request.Header), target) if err != nil { return err } if custom { return nil } return p.bindValue(data, hasKey, target) case "path": data, custom, hasKey, err := p.readValue(routeParams, target) if err != nil { return err } if custom { return nil } return p.bindValue(data, hasKey, target) case "formData": var err error var mt string mt, _, e := httpkit.ContentType(request.Header) if e != nil { // because of the interface conversion go thinks the error is not nil // so we first check for nil and then set the err var if it's not nil err = e } if err != nil { return errors.InvalidContentType("", []string{"multipart/form-data", "application/x-www-form-urlencoded"}) } if mt != "multipart/form-data" && mt != "application/x-www-form-urlencoded" { return errors.InvalidContentType(mt, []string{"multipart/form-data", "application/x-www-form-urlencoded"}) } if mt == "multipart/form-data" { if err := request.ParseMultipartForm(defaultMaxMemory); err != nil { return errors.NewParseError(p.Name, p.parameter.In, "", err) } } if err := request.ParseForm(); err != nil { return errors.NewParseError(p.Name, p.parameter.In, "", err) } if p.parameter.Type == "file" { file, header, err := request.FormFile(p.parameter.Name) if err != nil { return errors.NewParseError(p.Name, p.parameter.In, "", err) } target.Set(reflect.ValueOf(httpkit.File{Data: file, Header: header})) return nil } if request.MultipartForm != nil { data, custom, hasKey, err := p.readValue(httpkit.Values(request.MultipartForm.Value), target) if err != nil { return err } if custom { return nil } return p.bindValue(data, hasKey, target) } data, custom, hasKey, err := p.readValue(httpkit.Values(request.PostForm), target) if err != nil { return err } if custom { return nil } return p.bindValue(data, hasKey, target) case "body": newValue := reflect.New(target.Type()) if !httpkit.HasBody(request) { if p.parameter.Default != nil { target.Set(reflect.ValueOf(p.parameter.Default)) } return nil } if err := consumer.Consume(request.Body, newValue.Interface()); err != nil { if err == io.EOF && p.parameter.Default != nil { target.Set(reflect.ValueOf(p.parameter.Default)) return nil } tpe := p.parameter.Type if p.parameter.Format != "" { tpe = p.parameter.Format } return errors.InvalidType(p.Name, p.parameter.In, tpe, nil) } target.Set(reflect.Indirect(newValue)) return nil default: return errors.New(500, fmt.Sprintf("invalid parameter location %q", p.parameter.In)) } }