github.com/kaisawind/go-swagger@v0.19.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  	"io"
    10  	"net/http"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/runtime"
    14  	"github.com/go-openapi/runtime/middleware"
    15  
    16  	models "github.com/go-swagger/go-swagger/examples/composed-auth/models"
    17  )
    18  
    19  // NewAddOrderParams creates a new AddOrderParams object
    20  // no default values defined in spec.
    21  func NewAddOrderParams() AddOrderParams {
    22  
    23  	return AddOrderParams{}
    24  }
    25  
    26  // AddOrderParams contains all the bound params for the add order operation
    27  // typically these are obtained from a http.Request
    28  //
    29  // swagger:parameters AddOrder
    30  type AddOrderParams struct {
    31  
    32  	// HTTP Request Object
    33  	HTTPRequest *http.Request `json:"-"`
    34  
    35  	/*
    36  	  Required: true
    37  	  In: body
    38  	*/
    39  	Order *models.Order
    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 NewAddOrderParams() beforehand.
    46  func (o *AddOrderParams) 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.Order
    54  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    55  			if err == io.EOF {
    56  				res = append(res, errors.Required("order", "body"))
    57  			} else {
    58  				res = append(res, errors.NewParseError("order", "body", "", err))
    59  			}
    60  		} else {
    61  			// validate body object
    62  			if err := body.Validate(route.Formats); err != nil {
    63  				res = append(res, err)
    64  			}
    65  
    66  			if len(res) == 0 {
    67  				o.Order = &body
    68  			}
    69  		}
    70  	} else {
    71  		res = append(res, errors.Required("order", "body"))
    72  	}
    73  	if len(res) > 0 {
    74  		return errors.CompositeValidationError(res...)
    75  	}
    76  	return nil
    77  }