github.com/weaviate/weaviate@v1.24.6/entities/models/patch_document_object.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 models
    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  	"context"
    21  	"encoding/json"
    22  
    23  	"github.com/go-openapi/errors"
    24  	"github.com/go-openapi/strfmt"
    25  	"github.com/go-openapi/swag"
    26  	"github.com/go-openapi/validate"
    27  )
    28  
    29  // PatchDocumentObject Either a JSONPatch document as defined by RFC 6902 (from, op, path, value), or a merge document (RFC 7396).
    30  //
    31  // swagger:model PatchDocumentObject
    32  type PatchDocumentObject struct {
    33  
    34  	// A string containing a JSON Pointer value.
    35  	From string `json:"from,omitempty"`
    36  
    37  	// merge
    38  	Merge *Object `json:"merge,omitempty"`
    39  
    40  	// The operation to be performed.
    41  	// Required: true
    42  	// Enum: [add remove replace move copy test]
    43  	Op *string `json:"op"`
    44  
    45  	// A JSON-Pointer.
    46  	// Required: true
    47  	Path *string `json:"path"`
    48  
    49  	// The value to be used within the operations.
    50  	Value interface{} `json:"value,omitempty"`
    51  }
    52  
    53  // Validate validates this patch document object
    54  func (m *PatchDocumentObject) Validate(formats strfmt.Registry) error {
    55  	var res []error
    56  
    57  	if err := m.validateMerge(formats); err != nil {
    58  		res = append(res, err)
    59  	}
    60  
    61  	if err := m.validateOp(formats); err != nil {
    62  		res = append(res, err)
    63  	}
    64  
    65  	if err := m.validatePath(formats); err != nil {
    66  		res = append(res, err)
    67  	}
    68  
    69  	if len(res) > 0 {
    70  		return errors.CompositeValidationError(res...)
    71  	}
    72  	return nil
    73  }
    74  
    75  func (m *PatchDocumentObject) validateMerge(formats strfmt.Registry) error {
    76  	if swag.IsZero(m.Merge) { // not required
    77  		return nil
    78  	}
    79  
    80  	if m.Merge != nil {
    81  		if err := m.Merge.Validate(formats); err != nil {
    82  			if ve, ok := err.(*errors.Validation); ok {
    83  				return ve.ValidateName("merge")
    84  			} else if ce, ok := err.(*errors.CompositeError); ok {
    85  				return ce.ValidateName("merge")
    86  			}
    87  			return err
    88  		}
    89  	}
    90  
    91  	return nil
    92  }
    93  
    94  var patchDocumentObjectTypeOpPropEnum []interface{}
    95  
    96  func init() {
    97  	var res []string
    98  	if err := json.Unmarshal([]byte(`["add","remove","replace","move","copy","test"]`), &res); err != nil {
    99  		panic(err)
   100  	}
   101  	for _, v := range res {
   102  		patchDocumentObjectTypeOpPropEnum = append(patchDocumentObjectTypeOpPropEnum, v)
   103  	}
   104  }
   105  
   106  const (
   107  
   108  	// PatchDocumentObjectOpAdd captures enum value "add"
   109  	PatchDocumentObjectOpAdd string = "add"
   110  
   111  	// PatchDocumentObjectOpRemove captures enum value "remove"
   112  	PatchDocumentObjectOpRemove string = "remove"
   113  
   114  	// PatchDocumentObjectOpReplace captures enum value "replace"
   115  	PatchDocumentObjectOpReplace string = "replace"
   116  
   117  	// PatchDocumentObjectOpMove captures enum value "move"
   118  	PatchDocumentObjectOpMove string = "move"
   119  
   120  	// PatchDocumentObjectOpCopy captures enum value "copy"
   121  	PatchDocumentObjectOpCopy string = "copy"
   122  
   123  	// PatchDocumentObjectOpTest captures enum value "test"
   124  	PatchDocumentObjectOpTest string = "test"
   125  )
   126  
   127  // prop value enum
   128  func (m *PatchDocumentObject) validateOpEnum(path, location string, value string) error {
   129  	if err := validate.EnumCase(path, location, value, patchDocumentObjectTypeOpPropEnum, true); err != nil {
   130  		return err
   131  	}
   132  	return nil
   133  }
   134  
   135  func (m *PatchDocumentObject) validateOp(formats strfmt.Registry) error {
   136  
   137  	if err := validate.Required("op", "body", m.Op); err != nil {
   138  		return err
   139  	}
   140  
   141  	// value enum
   142  	if err := m.validateOpEnum("op", "body", *m.Op); err != nil {
   143  		return err
   144  	}
   145  
   146  	return nil
   147  }
   148  
   149  func (m *PatchDocumentObject) validatePath(formats strfmt.Registry) error {
   150  
   151  	if err := validate.Required("path", "body", m.Path); err != nil {
   152  		return err
   153  	}
   154  
   155  	return nil
   156  }
   157  
   158  // ContextValidate validate this patch document object based on the context it is used
   159  func (m *PatchDocumentObject) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   160  	var res []error
   161  
   162  	if err := m.contextValidateMerge(ctx, formats); err != nil {
   163  		res = append(res, err)
   164  	}
   165  
   166  	if len(res) > 0 {
   167  		return errors.CompositeValidationError(res...)
   168  	}
   169  	return nil
   170  }
   171  
   172  func (m *PatchDocumentObject) contextValidateMerge(ctx context.Context, formats strfmt.Registry) error {
   173  
   174  	if m.Merge != nil {
   175  		if err := m.Merge.ContextValidate(ctx, formats); err != nil {
   176  			if ve, ok := err.(*errors.Validation); ok {
   177  				return ve.ValidateName("merge")
   178  			} else if ce, ok := err.(*errors.CompositeError); ok {
   179  				return ce.ValidateName("merge")
   180  			}
   181  			return err
   182  		}
   183  	}
   184  
   185  	return nil
   186  }
   187  
   188  // MarshalBinary interface implementation
   189  func (m *PatchDocumentObject) MarshalBinary() ([]byte, error) {
   190  	if m == nil {
   191  		return nil, nil
   192  	}
   193  	return swag.WriteJSON(m)
   194  }
   195  
   196  // UnmarshalBinary interface implementation
   197  func (m *PatchDocumentObject) UnmarshalBinary(b []byte) error {
   198  	var res PatchDocumentObject
   199  	if err := swag.ReadJSON(b, &res); err != nil {
   200  		return err
   201  	}
   202  	*m = res
   203  	return nil
   204  }