github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/pet/update_pet_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package pet
     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  	"net/http"
    10  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/runtime"
    13  	"github.com/go-openapi/runtime/middleware"
    14  	"github.com/go-openapi/validate"
    15  
    16  	"github.com/thetreep/go-swagger/examples/generated/models"
    17  )
    18  
    19  // NewUpdatePetParams creates a new UpdatePetParams object
    20  //
    21  // There are no default values defined in the spec.
    22  func NewUpdatePetParams() UpdatePetParams {
    23  
    24  	return UpdatePetParams{}
    25  }
    26  
    27  // UpdatePetParams contains all the bound params for the update pet operation
    28  // typically these are obtained from a http.Request
    29  //
    30  // swagger:parameters updatePet
    31  type UpdatePetParams struct {
    32  
    33  	// HTTP Request Object
    34  	HTTPRequest *http.Request `json:"-"`
    35  
    36  	/*Pet object that needs to be added to the store
    37  	  In: body
    38  	*/
    39  	Body *models.Pet
    40  }
    41  
    42  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    43  // for simple values it will use straight method calls.
    44  //
    45  // To ensure default values, the struct must have been initialized with NewUpdatePetParams() beforehand.
    46  func (o *UpdatePetParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    47  	var res []error
    48  
    49  	o.HTTPRequest = r
    50  
    51  	if runtime.HasBody(r) {
    52  		defer r.Body.Close()
    53  		var body models.Pet
    54  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    55  			res = append(res, errors.NewParseError("body", "body", "", err))
    56  		} else {
    57  			// validate body object
    58  			if err := body.Validate(route.Formats); err != nil {
    59  				res = append(res, err)
    60  			}
    61  
    62  			ctx := validate.WithOperationRequest(r.Context())
    63  			if err := body.ContextValidate(ctx, route.Formats); err != nil {
    64  				res = append(res, err)
    65  			}
    66  
    67  			if len(res) == 0 {
    68  				o.Body = &body
    69  			}
    70  		}
    71  	}
    72  	if len(res) > 0 {
    73  		return errors.CompositeValidationError(res...)
    74  	}
    75  	return nil
    76  }