github.com/weaviate/weaviate@v1.24.6/entities/models/patch_document_action.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 // PatchDocumentAction Either a JSONPatch document as defined by RFC 6902 (from, op, path, value), or a merge document (RFC 7396). 30 // 31 // swagger:model PatchDocumentAction 32 type PatchDocumentAction 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 action 54 func (m *PatchDocumentAction) 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 *PatchDocumentAction) 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 patchDocumentActionTypeOpPropEnum []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 patchDocumentActionTypeOpPropEnum = append(patchDocumentActionTypeOpPropEnum, v) 103 } 104 } 105 106 const ( 107 108 // PatchDocumentActionOpAdd captures enum value "add" 109 PatchDocumentActionOpAdd string = "add" 110 111 // PatchDocumentActionOpRemove captures enum value "remove" 112 PatchDocumentActionOpRemove string = "remove" 113 114 // PatchDocumentActionOpReplace captures enum value "replace" 115 PatchDocumentActionOpReplace string = "replace" 116 117 // PatchDocumentActionOpMove captures enum value "move" 118 PatchDocumentActionOpMove string = "move" 119 120 // PatchDocumentActionOpCopy captures enum value "copy" 121 PatchDocumentActionOpCopy string = "copy" 122 123 // PatchDocumentActionOpTest captures enum value "test" 124 PatchDocumentActionOpTest string = "test" 125 ) 126 127 // prop value enum 128 func (m *PatchDocumentAction) validateOpEnum(path, location string, value string) error { 129 if err := validate.EnumCase(path, location, value, patchDocumentActionTypeOpPropEnum, true); err != nil { 130 return err 131 } 132 return nil 133 } 134 135 func (m *PatchDocumentAction) 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 *PatchDocumentAction) 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 action based on the context it is used 159 func (m *PatchDocumentAction) 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 *PatchDocumentAction) 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 *PatchDocumentAction) 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 *PatchDocumentAction) UnmarshalBinary(b []byte) error { 198 var res PatchDocumentAction 199 if err := swag.ReadJSON(b, &res); err != nil { 200 return err 201 } 202 *m = res 203 return nil 204 }