github.com/weaviate/weaviate@v1.24.6/entities/models/single_ref.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 22 "github.com/go-openapi/errors" 23 "github.com/go-openapi/strfmt" 24 "github.com/go-openapi/swag" 25 "github.com/go-openapi/validate" 26 ) 27 28 // SingleRef Either set beacon (direct reference) or set class and schema (concept reference) 29 // 30 // swagger:model SingleRef 31 type SingleRef struct { 32 33 // If using a direct reference, specify the URI to point to the cross-ref here. Should be in the form of weaviate://localhost/<uuid> for the example of a local cross-ref to an object 34 // Format: uri 35 Beacon strfmt.URI `json:"beacon,omitempty"` 36 37 // If using a concept reference (rather than a direct reference), specify the desired class name here 38 // Format: uri 39 Class strfmt.URI `json:"class,omitempty"` 40 41 // Additional Meta information about classifications if the item was part of one 42 Classification *ReferenceMetaClassification `json:"classification,omitempty"` 43 44 // If using a direct reference, this read-only fields provides a link to the referenced resource. If 'origin' is globally configured, an absolute URI is shown - a relative URI otherwise. 45 // Format: uri 46 Href strfmt.URI `json:"href,omitempty"` 47 48 // If using a concept reference (rather than a direct reference), specify the desired properties here 49 Schema PropertySchema `json:"schema,omitempty"` 50 } 51 52 // Validate validates this single ref 53 func (m *SingleRef) Validate(formats strfmt.Registry) error { 54 var res []error 55 56 if err := m.validateBeacon(formats); err != nil { 57 res = append(res, err) 58 } 59 60 if err := m.validateClass(formats); err != nil { 61 res = append(res, err) 62 } 63 64 if err := m.validateClassification(formats); err != nil { 65 res = append(res, err) 66 } 67 68 if err := m.validateHref(formats); err != nil { 69 res = append(res, err) 70 } 71 72 if len(res) > 0 { 73 return errors.CompositeValidationError(res...) 74 } 75 return nil 76 } 77 78 func (m *SingleRef) validateBeacon(formats strfmt.Registry) error { 79 if swag.IsZero(m.Beacon) { // not required 80 return nil 81 } 82 83 if err := validate.FormatOf("beacon", "body", "uri", m.Beacon.String(), formats); err != nil { 84 return err 85 } 86 87 return nil 88 } 89 90 func (m *SingleRef) validateClass(formats strfmt.Registry) error { 91 if swag.IsZero(m.Class) { // not required 92 return nil 93 } 94 95 if err := validate.FormatOf("class", "body", "uri", m.Class.String(), formats); err != nil { 96 return err 97 } 98 99 return nil 100 } 101 102 func (m *SingleRef) validateClassification(formats strfmt.Registry) error { 103 if swag.IsZero(m.Classification) { // not required 104 return nil 105 } 106 107 if m.Classification != nil { 108 if err := m.Classification.Validate(formats); err != nil { 109 if ve, ok := err.(*errors.Validation); ok { 110 return ve.ValidateName("classification") 111 } else if ce, ok := err.(*errors.CompositeError); ok { 112 return ce.ValidateName("classification") 113 } 114 return err 115 } 116 } 117 118 return nil 119 } 120 121 func (m *SingleRef) validateHref(formats strfmt.Registry) error { 122 if swag.IsZero(m.Href) { // not required 123 return nil 124 } 125 126 if err := validate.FormatOf("href", "body", "uri", m.Href.String(), formats); err != nil { 127 return err 128 } 129 130 return nil 131 } 132 133 // ContextValidate validate this single ref based on the context it is used 134 func (m *SingleRef) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 135 var res []error 136 137 if err := m.contextValidateClassification(ctx, formats); err != nil { 138 res = append(res, err) 139 } 140 141 if len(res) > 0 { 142 return errors.CompositeValidationError(res...) 143 } 144 return nil 145 } 146 147 func (m *SingleRef) contextValidateClassification(ctx context.Context, formats strfmt.Registry) error { 148 149 if m.Classification != nil { 150 if err := m.Classification.ContextValidate(ctx, formats); err != nil { 151 if ve, ok := err.(*errors.Validation); ok { 152 return ve.ValidateName("classification") 153 } else if ce, ok := err.(*errors.CompositeError); ok { 154 return ce.ValidateName("classification") 155 } 156 return err 157 } 158 } 159 160 return nil 161 } 162 163 // MarshalBinary interface implementation 164 func (m *SingleRef) MarshalBinary() ([]byte, error) { 165 if m == nil { 166 return nil, nil 167 } 168 return swag.WriteJSON(m) 169 } 170 171 // UnmarshalBinary interface implementation 172 func (m *SingleRef) UnmarshalBinary(b []byte) error { 173 var res SingleRef 174 if err := swag.ReadJSON(b, &res); err != nil { 175 return err 176 } 177 *m = res 178 return nil 179 }