github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/operations/objects/objects_patch_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 objects
    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  	"net/http"
    21  
    22  	"github.com/go-openapi/errors"
    23  	"github.com/go-openapi/runtime"
    24  	"github.com/go-openapi/runtime/middleware"
    25  	"github.com/go-openapi/strfmt"
    26  	"github.com/go-openapi/validate"
    27  
    28  	"github.com/weaviate/weaviate/entities/models"
    29  )
    30  
    31  // NewObjectsPatchParams creates a new ObjectsPatchParams object
    32  //
    33  // There are no default values defined in the spec.
    34  func NewObjectsPatchParams() ObjectsPatchParams {
    35  
    36  	return ObjectsPatchParams{}
    37  }
    38  
    39  // ObjectsPatchParams contains all the bound params for the objects patch operation
    40  // typically these are obtained from a http.Request
    41  //
    42  // swagger:parameters objects.patch
    43  type ObjectsPatchParams struct {
    44  
    45  	// HTTP Request Object
    46  	HTTPRequest *http.Request `json:"-"`
    47  
    48  	/*RFC 7396-style patch, the body contains the object to merge into the existing object.
    49  	  In: body
    50  	*/
    51  	Body *models.Object
    52  	/*Determines how many replicas must acknowledge a request before it is considered successful
    53  	  In: query
    54  	*/
    55  	ConsistencyLevel *string
    56  	/*Unique ID of the Object.
    57  	  Required: true
    58  	  In: path
    59  	*/
    60  	ID strfmt.UUID
    61  }
    62  
    63  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    64  // for simple values it will use straight method calls.
    65  //
    66  // To ensure default values, the struct must have been initialized with NewObjectsPatchParams() beforehand.
    67  func (o *ObjectsPatchParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    68  	var res []error
    69  
    70  	o.HTTPRequest = r
    71  
    72  	qs := runtime.Values(r.URL.Query())
    73  
    74  	if runtime.HasBody(r) {
    75  		defer r.Body.Close()
    76  		var body models.Object
    77  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    78  			res = append(res, errors.NewParseError("body", "body", "", err))
    79  		} else {
    80  			// validate body object
    81  			if err := body.Validate(route.Formats); err != nil {
    82  				res = append(res, err)
    83  			}
    84  
    85  			ctx := validate.WithOperationRequest(r.Context())
    86  			if err := body.ContextValidate(ctx, route.Formats); err != nil {
    87  				res = append(res, err)
    88  			}
    89  
    90  			if len(res) == 0 {
    91  				o.Body = &body
    92  			}
    93  		}
    94  	}
    95  
    96  	qConsistencyLevel, qhkConsistencyLevel, _ := qs.GetOK("consistency_level")
    97  	if err := o.bindConsistencyLevel(qConsistencyLevel, qhkConsistencyLevel, route.Formats); err != nil {
    98  		res = append(res, err)
    99  	}
   100  
   101  	rID, rhkID, _ := route.Params.GetOK("id")
   102  	if err := o.bindID(rID, rhkID, route.Formats); err != nil {
   103  		res = append(res, err)
   104  	}
   105  	if len(res) > 0 {
   106  		return errors.CompositeValidationError(res...)
   107  	}
   108  	return nil
   109  }
   110  
   111  // bindConsistencyLevel binds and validates parameter ConsistencyLevel from query.
   112  func (o *ObjectsPatchParams) bindConsistencyLevel(rawData []string, hasKey bool, formats strfmt.Registry) error {
   113  	var raw string
   114  	if len(rawData) > 0 {
   115  		raw = rawData[len(rawData)-1]
   116  	}
   117  
   118  	// Required: false
   119  	// AllowEmptyValue: false
   120  
   121  	if raw == "" { // empty values pass all other validations
   122  		return nil
   123  	}
   124  	o.ConsistencyLevel = &raw
   125  
   126  	return nil
   127  }
   128  
   129  // bindID binds and validates parameter ID from path.
   130  func (o *ObjectsPatchParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
   131  	var raw string
   132  	if len(rawData) > 0 {
   133  		raw = rawData[len(rawData)-1]
   134  	}
   135  
   136  	// Required: true
   137  	// Parameter is provided by construction from the route
   138  
   139  	// Format: uuid
   140  	value, err := formats.Parse("uuid", raw)
   141  	if err != nil {
   142  		return errors.InvalidType("id", "path", "strfmt.UUID", raw)
   143  	}
   144  	o.ID = *(value.(*strfmt.UUID))
   145  
   146  	if err := o.validateID(formats); err != nil {
   147  		return err
   148  	}
   149  
   150  	return nil
   151  }
   152  
   153  // validateID carries on validations for parameter ID
   154  func (o *ObjectsPatchParams) validateID(formats strfmt.Registry) error {
   155  
   156  	if err := validate.FormatOf("id", "path", "uuid", o.ID.String(), formats); err != nil {
   157  		return err
   158  	}
   159  	return nil
   160  }