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

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