github.com/weaviate/weaviate@v1.24.6/entities/models/class.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 "strconv" 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 // Class class 30 // 31 // swagger:model Class 32 type Class struct { 33 34 // Name of the class as URI relative to the schema URL. 35 Class string `json:"class,omitempty"` 36 37 // Description of the class. 38 Description string `json:"description,omitempty"` 39 40 // inverted index config 41 InvertedIndexConfig *InvertedIndexConfig `json:"invertedIndexConfig,omitempty"` 42 43 // Configuration specific to modules this Weaviate instance has installed 44 ModuleConfig interface{} `json:"moduleConfig,omitempty"` 45 46 // multi tenancy config 47 MultiTenancyConfig *MultiTenancyConfig `json:"multiTenancyConfig,omitempty"` 48 49 // The properties of the class. 50 Properties []*Property `json:"properties"` 51 52 // replication config 53 ReplicationConfig *ReplicationConfig `json:"replicationConfig,omitempty"` 54 55 // Manage how the index should be sharded and distributed in the cluster 56 ShardingConfig interface{} `json:"shardingConfig,omitempty"` 57 58 // vector config 59 VectorConfig map[string]VectorConfig `json:"vectorConfig,omitempty"` 60 61 // Vector-index config, that is specific to the type of index selected in vectorIndexType 62 VectorIndexConfig interface{} `json:"vectorIndexConfig,omitempty"` 63 64 // Name of the vector index to use, eg. (HNSW) 65 VectorIndexType string `json:"vectorIndexType,omitempty"` 66 67 // Specify how the vectors for this class should be determined. The options are either 'none' - this means you have to import a vector with each object yourself - or the name of a module that provides vectorization capabilities, such as 'text2vec-contextionary'. If left empty, it will use the globally configured default which can itself either be 'none' or a specific module. 68 Vectorizer string `json:"vectorizer,omitempty"` 69 } 70 71 // Validate validates this class 72 func (m *Class) Validate(formats strfmt.Registry) error { 73 var res []error 74 75 if err := m.validateInvertedIndexConfig(formats); err != nil { 76 res = append(res, err) 77 } 78 79 if err := m.validateMultiTenancyConfig(formats); err != nil { 80 res = append(res, err) 81 } 82 83 if err := m.validateProperties(formats); err != nil { 84 res = append(res, err) 85 } 86 87 if err := m.validateReplicationConfig(formats); err != nil { 88 res = append(res, err) 89 } 90 91 if err := m.validateVectorConfig(formats); err != nil { 92 res = append(res, err) 93 } 94 95 if len(res) > 0 { 96 return errors.CompositeValidationError(res...) 97 } 98 return nil 99 } 100 101 func (m *Class) validateInvertedIndexConfig(formats strfmt.Registry) error { 102 if swag.IsZero(m.InvertedIndexConfig) { // not required 103 return nil 104 } 105 106 if m.InvertedIndexConfig != nil { 107 if err := m.InvertedIndexConfig.Validate(formats); err != nil { 108 if ve, ok := err.(*errors.Validation); ok { 109 return ve.ValidateName("invertedIndexConfig") 110 } else if ce, ok := err.(*errors.CompositeError); ok { 111 return ce.ValidateName("invertedIndexConfig") 112 } 113 return err 114 } 115 } 116 117 return nil 118 } 119 120 func (m *Class) validateMultiTenancyConfig(formats strfmt.Registry) error { 121 if swag.IsZero(m.MultiTenancyConfig) { // not required 122 return nil 123 } 124 125 if m.MultiTenancyConfig != nil { 126 if err := m.MultiTenancyConfig.Validate(formats); err != nil { 127 if ve, ok := err.(*errors.Validation); ok { 128 return ve.ValidateName("multiTenancyConfig") 129 } else if ce, ok := err.(*errors.CompositeError); ok { 130 return ce.ValidateName("multiTenancyConfig") 131 } 132 return err 133 } 134 } 135 136 return nil 137 } 138 139 func (m *Class) validateProperties(formats strfmt.Registry) error { 140 if swag.IsZero(m.Properties) { // not required 141 return nil 142 } 143 144 for i := 0; i < len(m.Properties); i++ { 145 if swag.IsZero(m.Properties[i]) { // not required 146 continue 147 } 148 149 if m.Properties[i] != nil { 150 if err := m.Properties[i].Validate(formats); err != nil { 151 if ve, ok := err.(*errors.Validation); ok { 152 return ve.ValidateName("properties" + "." + strconv.Itoa(i)) 153 } else if ce, ok := err.(*errors.CompositeError); ok { 154 return ce.ValidateName("properties" + "." + strconv.Itoa(i)) 155 } 156 return err 157 } 158 } 159 160 } 161 162 return nil 163 } 164 165 func (m *Class) validateReplicationConfig(formats strfmt.Registry) error { 166 if swag.IsZero(m.ReplicationConfig) { // not required 167 return nil 168 } 169 170 if m.ReplicationConfig != nil { 171 if err := m.ReplicationConfig.Validate(formats); err != nil { 172 if ve, ok := err.(*errors.Validation); ok { 173 return ve.ValidateName("replicationConfig") 174 } else if ce, ok := err.(*errors.CompositeError); ok { 175 return ce.ValidateName("replicationConfig") 176 } 177 return err 178 } 179 } 180 181 return nil 182 } 183 184 func (m *Class) validateVectorConfig(formats strfmt.Registry) error { 185 if swag.IsZero(m.VectorConfig) { // not required 186 return nil 187 } 188 189 for k := range m.VectorConfig { 190 191 if err := validate.Required("vectorConfig"+"."+k, "body", m.VectorConfig[k]); err != nil { 192 return err 193 } 194 if val, ok := m.VectorConfig[k]; ok { 195 if err := val.Validate(formats); err != nil { 196 if ve, ok := err.(*errors.Validation); ok { 197 return ve.ValidateName("vectorConfig" + "." + k) 198 } else if ce, ok := err.(*errors.CompositeError); ok { 199 return ce.ValidateName("vectorConfig" + "." + k) 200 } 201 return err 202 } 203 } 204 205 } 206 207 return nil 208 } 209 210 // ContextValidate validate this class based on the context it is used 211 func (m *Class) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 212 var res []error 213 214 if err := m.contextValidateInvertedIndexConfig(ctx, formats); err != nil { 215 res = append(res, err) 216 } 217 218 if err := m.contextValidateMultiTenancyConfig(ctx, formats); err != nil { 219 res = append(res, err) 220 } 221 222 if err := m.contextValidateProperties(ctx, formats); err != nil { 223 res = append(res, err) 224 } 225 226 if err := m.contextValidateReplicationConfig(ctx, formats); err != nil { 227 res = append(res, err) 228 } 229 230 if err := m.contextValidateVectorConfig(ctx, formats); err != nil { 231 res = append(res, err) 232 } 233 234 if len(res) > 0 { 235 return errors.CompositeValidationError(res...) 236 } 237 return nil 238 } 239 240 func (m *Class) contextValidateInvertedIndexConfig(ctx context.Context, formats strfmt.Registry) error { 241 242 if m.InvertedIndexConfig != nil { 243 if err := m.InvertedIndexConfig.ContextValidate(ctx, formats); err != nil { 244 if ve, ok := err.(*errors.Validation); ok { 245 return ve.ValidateName("invertedIndexConfig") 246 } else if ce, ok := err.(*errors.CompositeError); ok { 247 return ce.ValidateName("invertedIndexConfig") 248 } 249 return err 250 } 251 } 252 253 return nil 254 } 255 256 func (m *Class) contextValidateMultiTenancyConfig(ctx context.Context, formats strfmt.Registry) error { 257 258 if m.MultiTenancyConfig != nil { 259 if err := m.MultiTenancyConfig.ContextValidate(ctx, formats); err != nil { 260 if ve, ok := err.(*errors.Validation); ok { 261 return ve.ValidateName("multiTenancyConfig") 262 } else if ce, ok := err.(*errors.CompositeError); ok { 263 return ce.ValidateName("multiTenancyConfig") 264 } 265 return err 266 } 267 } 268 269 return nil 270 } 271 272 func (m *Class) contextValidateProperties(ctx context.Context, formats strfmt.Registry) error { 273 274 for i := 0; i < len(m.Properties); i++ { 275 276 if m.Properties[i] != nil { 277 if err := m.Properties[i].ContextValidate(ctx, formats); err != nil { 278 if ve, ok := err.(*errors.Validation); ok { 279 return ve.ValidateName("properties" + "." + strconv.Itoa(i)) 280 } else if ce, ok := err.(*errors.CompositeError); ok { 281 return ce.ValidateName("properties" + "." + strconv.Itoa(i)) 282 } 283 return err 284 } 285 } 286 287 } 288 289 return nil 290 } 291 292 func (m *Class) contextValidateReplicationConfig(ctx context.Context, formats strfmt.Registry) error { 293 294 if m.ReplicationConfig != nil { 295 if err := m.ReplicationConfig.ContextValidate(ctx, formats); err != nil { 296 if ve, ok := err.(*errors.Validation); ok { 297 return ve.ValidateName("replicationConfig") 298 } else if ce, ok := err.(*errors.CompositeError); ok { 299 return ce.ValidateName("replicationConfig") 300 } 301 return err 302 } 303 } 304 305 return nil 306 } 307 308 func (m *Class) contextValidateVectorConfig(ctx context.Context, formats strfmt.Registry) error { 309 310 for k := range m.VectorConfig { 311 312 if val, ok := m.VectorConfig[k]; ok { 313 if err := val.ContextValidate(ctx, formats); err != nil { 314 return err 315 } 316 } 317 318 } 319 320 return nil 321 } 322 323 // MarshalBinary interface implementation 324 func (m *Class) MarshalBinary() ([]byte, error) { 325 if m == nil { 326 return nil, nil 327 } 328 return swag.WriteJSON(m) 329 } 330 331 // UnmarshalBinary interface implementation 332 func (m *Class) UnmarshalBinary(b []byte) error { 333 var res Class 334 if err := swag.ReadJSON(b, &res); err != nil { 335 return err 336 } 337 *m = res 338 return nil 339 }