github.com/circl-dev/go-swagger@v0.31.0/examples/contributed-templates/stratoscale/restapi/operations/store/order_create_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package store
     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/contributed-templates/stratoscale/models"
    19  )
    20  
    21  // NewOrderCreateParams creates a new OrderCreateParams object
    22  //
    23  // There are no default values defined in the spec.
    24  func NewOrderCreateParams() OrderCreateParams {
    25  
    26  	return OrderCreateParams{}
    27  }
    28  
    29  // OrderCreateParams contains all the bound params for the order create operation
    30  // typically these are obtained from a http.Request
    31  //
    32  // swagger:parameters OrderCreate
    33  type OrderCreateParams struct {
    34  
    35  	// HTTP Request Object
    36  	HTTPRequest *http.Request `json:"-"`
    37  
    38  	/*order placed for purchasing the pet
    39  	  Required: true
    40  	  In: body
    41  	*/
    42  	Body *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 NewOrderCreateParams() beforehand.
    49  func (o *OrderCreateParams) 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("body", "body", ""))
    60  			} else {
    61  				res = append(res, errors.NewParseError("body", "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.Body = &body
    76  			}
    77  		}
    78  	} else {
    79  		res = append(res, errors.Required("body", "body", ""))
    80  	}
    81  	if len(res) > 0 {
    82  		return errors.CompositeValidationError(res...)
    83  	}
    84  	return nil
    85  }