github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/operations/graphql/graphql_post_parameters.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  // Code generated by go-swagger; DO NOT EDIT.
    13  
    14  package graphql
    15  
    16  // This file was generated by the swagger tool.
    17  // Editing this file might prove futile when you re-run the swagger generate command
    18  
    19  import (
    20  	"io"
    21  	"net/http"
    22  
    23  	"github.com/go-openapi/errors"
    24  	"github.com/go-openapi/runtime"
    25  	"github.com/go-openapi/runtime/middleware"
    26  	"github.com/go-openapi/validate"
    27  
    28  	"github.com/weaviate/weaviate/entities/models"
    29  )
    30  
    31  // NewGraphqlPostParams creates a new GraphqlPostParams object
    32  //
    33  // There are no default values defined in the spec.
    34  func NewGraphqlPostParams() GraphqlPostParams {
    35  
    36  	return GraphqlPostParams{}
    37  }
    38  
    39  // GraphqlPostParams contains all the bound params for the graphql post operation
    40  // typically these are obtained from a http.Request
    41  //
    42  // swagger:parameters graphql.post
    43  type GraphqlPostParams struct {
    44  
    45  	// HTTP Request Object
    46  	HTTPRequest *http.Request `json:"-"`
    47  
    48  	/*The GraphQL query request parameters.
    49  	  Required: true
    50  	  In: body
    51  	*/
    52  	Body *models.GraphQLQuery
    53  }
    54  
    55  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    56  // for simple values it will use straight method calls.
    57  //
    58  // To ensure default values, the struct must have been initialized with NewGraphqlPostParams() beforehand.
    59  func (o *GraphqlPostParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    60  	var res []error
    61  
    62  	o.HTTPRequest = r
    63  
    64  	if runtime.HasBody(r) {
    65  		defer r.Body.Close()
    66  		var body models.GraphQLQuery
    67  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    68  			if err == io.EOF {
    69  				res = append(res, errors.Required("body", "body", ""))
    70  			} else {
    71  				res = append(res, errors.NewParseError("body", "body", "", err))
    72  			}
    73  		} else {
    74  			// validate body object
    75  			if err := body.Validate(route.Formats); err != nil {
    76  				res = append(res, err)
    77  			}
    78  
    79  			ctx := validate.WithOperationRequest(r.Context())
    80  			if err := body.ContextValidate(ctx, route.Formats); err != nil {
    81  				res = append(res, err)
    82  			}
    83  
    84  			if len(res) == 0 {
    85  				o.Body = &body
    86  			}
    87  		}
    88  	} else {
    89  		res = append(res, errors.Required("body", "body", ""))
    90  	}
    91  	if len(res) > 0 {
    92  		return errors.CompositeValidationError(res...)
    93  	}
    94  	return nil
    95  }