github.com/weaviate/weaviate@v1.24.6/entities/models/schema.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 // Schema Definitions of semantic schemas (also see: https://github.com/weaviate/weaviate-semantic-schemas). 30 // 31 // swagger:model Schema 32 type Schema struct { 33 34 // Semantic classes that are available. 35 Classes []*Class `json:"classes"` 36 37 // Email of the maintainer. 38 // Format: email 39 Maintainer strfmt.Email `json:"maintainer,omitempty"` 40 41 // Name of the schema. 42 Name string `json:"name,omitempty"` 43 } 44 45 // Validate validates this schema 46 func (m *Schema) Validate(formats strfmt.Registry) error { 47 var res []error 48 49 if err := m.validateClasses(formats); err != nil { 50 res = append(res, err) 51 } 52 53 if err := m.validateMaintainer(formats); err != nil { 54 res = append(res, err) 55 } 56 57 if len(res) > 0 { 58 return errors.CompositeValidationError(res...) 59 } 60 return nil 61 } 62 63 func (m *Schema) validateClasses(formats strfmt.Registry) error { 64 if swag.IsZero(m.Classes) { // not required 65 return nil 66 } 67 68 for i := 0; i < len(m.Classes); i++ { 69 if swag.IsZero(m.Classes[i]) { // not required 70 continue 71 } 72 73 if m.Classes[i] != nil { 74 if err := m.Classes[i].Validate(formats); err != nil { 75 if ve, ok := err.(*errors.Validation); ok { 76 return ve.ValidateName("classes" + "." + strconv.Itoa(i)) 77 } else if ce, ok := err.(*errors.CompositeError); ok { 78 return ce.ValidateName("classes" + "." + strconv.Itoa(i)) 79 } 80 return err 81 } 82 } 83 84 } 85 86 return nil 87 } 88 89 func (m *Schema) validateMaintainer(formats strfmt.Registry) error { 90 if swag.IsZero(m.Maintainer) { // not required 91 return nil 92 } 93 94 if err := validate.FormatOf("maintainer", "body", "email", m.Maintainer.String(), formats); err != nil { 95 return err 96 } 97 98 return nil 99 } 100 101 // ContextValidate validate this schema based on the context it is used 102 func (m *Schema) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 103 var res []error 104 105 if err := m.contextValidateClasses(ctx, formats); err != nil { 106 res = append(res, err) 107 } 108 109 if len(res) > 0 { 110 return errors.CompositeValidationError(res...) 111 } 112 return nil 113 } 114 115 func (m *Schema) contextValidateClasses(ctx context.Context, formats strfmt.Registry) error { 116 117 for i := 0; i < len(m.Classes); i++ { 118 119 if m.Classes[i] != nil { 120 if err := m.Classes[i].ContextValidate(ctx, formats); err != nil { 121 if ve, ok := err.(*errors.Validation); ok { 122 return ve.ValidateName("classes" + "." + strconv.Itoa(i)) 123 } else if ce, ok := err.(*errors.CompositeError); ok { 124 return ce.ValidateName("classes" + "." + strconv.Itoa(i)) 125 } 126 return err 127 } 128 } 129 130 } 131 132 return nil 133 } 134 135 // MarshalBinary interface implementation 136 func (m *Schema) MarshalBinary() ([]byte, error) { 137 if m == nil { 138 return nil, nil 139 } 140 return swag.WriteJSON(m) 141 } 142 143 // UnmarshalBinary interface implementation 144 func (m *Schema) UnmarshalBinary(b []byte) error { 145 var res Schema 146 if err := swag.ReadJSON(b, &res); err != nil { 147 return err 148 } 149 *m = res 150 return nil 151 }