github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_aggregate.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 // Copyright 2020 The go-netbox Authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // 17 18 package models 19 20 // This file was generated by the swagger tool. 21 // Editing this file might prove futile when you re-run the swagger generate command 22 23 import ( 24 "context" 25 "strconv" 26 27 "github.com/go-openapi/errors" 28 "github.com/go-openapi/strfmt" 29 "github.com/go-openapi/swag" 30 "github.com/go-openapi/validate" 31 ) 32 33 // WritableAggregate writable aggregate 34 // 35 // swagger:model WritableAggregate 36 type WritableAggregate struct { 37 38 // Created 39 // Read Only: true 40 // Format: date 41 Created strfmt.Date `json:"created,omitempty"` 42 43 // Custom fields 44 CustomFields interface{} `json:"custom_fields,omitempty"` 45 46 // Date added 47 // Format: date 48 DateAdded *strfmt.Date `json:"date_added,omitempty"` 49 50 // Description 51 // Max Length: 200 52 Description string `json:"description,omitempty"` 53 54 // Display 55 // Read Only: true 56 Display string `json:"display,omitempty"` 57 58 // Family 59 // Read Only: true 60 Family string `json:"family,omitempty"` 61 62 // Id 63 // Read Only: true 64 ID int64 `json:"id,omitempty"` 65 66 // Last updated 67 // Read Only: true 68 // Format: date-time 69 LastUpdated strfmt.DateTime `json:"last_updated,omitempty"` 70 71 // Prefix 72 // Required: true 73 Prefix *string `json:"prefix"` 74 75 // RIR 76 // Required: true 77 Rir *int64 `json:"rir"` 78 79 // tags 80 Tags []*NestedTag `json:"tags"` 81 82 // Tenant 83 Tenant *int64 `json:"tenant,omitempty"` 84 85 // Url 86 // Read Only: true 87 // Format: uri 88 URL strfmt.URI `json:"url,omitempty"` 89 } 90 91 // Validate validates this writable aggregate 92 func (m *WritableAggregate) Validate(formats strfmt.Registry) error { 93 var res []error 94 95 if err := m.validateCreated(formats); err != nil { 96 res = append(res, err) 97 } 98 99 if err := m.validateDateAdded(formats); err != nil { 100 res = append(res, err) 101 } 102 103 if err := m.validateDescription(formats); err != nil { 104 res = append(res, err) 105 } 106 107 if err := m.validateLastUpdated(formats); err != nil { 108 res = append(res, err) 109 } 110 111 if err := m.validatePrefix(formats); err != nil { 112 res = append(res, err) 113 } 114 115 if err := m.validateRir(formats); err != nil { 116 res = append(res, err) 117 } 118 119 if err := m.validateTags(formats); err != nil { 120 res = append(res, err) 121 } 122 123 if err := m.validateURL(formats); err != nil { 124 res = append(res, err) 125 } 126 127 if len(res) > 0 { 128 return errors.CompositeValidationError(res...) 129 } 130 return nil 131 } 132 133 func (m *WritableAggregate) validateCreated(formats strfmt.Registry) error { 134 if swag.IsZero(m.Created) { // not required 135 return nil 136 } 137 138 if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil { 139 return err 140 } 141 142 return nil 143 } 144 145 func (m *WritableAggregate) validateDateAdded(formats strfmt.Registry) error { 146 if swag.IsZero(m.DateAdded) { // not required 147 return nil 148 } 149 150 if err := validate.FormatOf("date_added", "body", "date", m.DateAdded.String(), formats); err != nil { 151 return err 152 } 153 154 return nil 155 } 156 157 func (m *WritableAggregate) validateDescription(formats strfmt.Registry) error { 158 if swag.IsZero(m.Description) { // not required 159 return nil 160 } 161 162 if err := validate.MaxLength("description", "body", m.Description, 200); err != nil { 163 return err 164 } 165 166 return nil 167 } 168 169 func (m *WritableAggregate) validateLastUpdated(formats strfmt.Registry) error { 170 if swag.IsZero(m.LastUpdated) { // not required 171 return nil 172 } 173 174 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 175 return err 176 } 177 178 return nil 179 } 180 181 func (m *WritableAggregate) validatePrefix(formats strfmt.Registry) error { 182 183 if err := validate.Required("prefix", "body", m.Prefix); err != nil { 184 return err 185 } 186 187 return nil 188 } 189 190 func (m *WritableAggregate) validateRir(formats strfmt.Registry) error { 191 192 if err := validate.Required("rir", "body", m.Rir); err != nil { 193 return err 194 } 195 196 return nil 197 } 198 199 func (m *WritableAggregate) validateTags(formats strfmt.Registry) error { 200 if swag.IsZero(m.Tags) { // not required 201 return nil 202 } 203 204 for i := 0; i < len(m.Tags); i++ { 205 if swag.IsZero(m.Tags[i]) { // not required 206 continue 207 } 208 209 if m.Tags[i] != nil { 210 if err := m.Tags[i].Validate(formats); err != nil { 211 if ve, ok := err.(*errors.Validation); ok { 212 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 213 } else if ce, ok := err.(*errors.CompositeError); ok { 214 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 215 } 216 return err 217 } 218 } 219 220 } 221 222 return nil 223 } 224 225 func (m *WritableAggregate) validateURL(formats strfmt.Registry) error { 226 if swag.IsZero(m.URL) { // not required 227 return nil 228 } 229 230 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 231 return err 232 } 233 234 return nil 235 } 236 237 // ContextValidate validate this writable aggregate based on the context it is used 238 func (m *WritableAggregate) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 239 var res []error 240 241 if err := m.contextValidateCreated(ctx, formats); err != nil { 242 res = append(res, err) 243 } 244 245 if err := m.contextValidateDisplay(ctx, formats); err != nil { 246 res = append(res, err) 247 } 248 249 if err := m.contextValidateFamily(ctx, formats); err != nil { 250 res = append(res, err) 251 } 252 253 if err := m.contextValidateID(ctx, formats); err != nil { 254 res = append(res, err) 255 } 256 257 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 258 res = append(res, err) 259 } 260 261 if err := m.contextValidateTags(ctx, formats); err != nil { 262 res = append(res, err) 263 } 264 265 if err := m.contextValidateURL(ctx, formats); err != nil { 266 res = append(res, err) 267 } 268 269 if len(res) > 0 { 270 return errors.CompositeValidationError(res...) 271 } 272 return nil 273 } 274 275 func (m *WritableAggregate) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error { 276 277 if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil { 278 return err 279 } 280 281 return nil 282 } 283 284 func (m *WritableAggregate) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 285 286 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 287 return err 288 } 289 290 return nil 291 } 292 293 func (m *WritableAggregate) contextValidateFamily(ctx context.Context, formats strfmt.Registry) error { 294 295 if err := validate.ReadOnly(ctx, "family", "body", string(m.Family)); err != nil { 296 return err 297 } 298 299 return nil 300 } 301 302 func (m *WritableAggregate) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 303 304 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 305 return err 306 } 307 308 return nil 309 } 310 311 func (m *WritableAggregate) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 312 313 if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 314 return err 315 } 316 317 return nil 318 } 319 320 func (m *WritableAggregate) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 321 322 for i := 0; i < len(m.Tags); i++ { 323 324 if m.Tags[i] != nil { 325 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 326 if ve, ok := err.(*errors.Validation); ok { 327 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 328 } else if ce, ok := err.(*errors.CompositeError); ok { 329 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 330 } 331 return err 332 } 333 } 334 335 } 336 337 return nil 338 } 339 340 func (m *WritableAggregate) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 341 342 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 343 return err 344 } 345 346 return nil 347 } 348 349 // MarshalBinary interface implementation 350 func (m *WritableAggregate) MarshalBinary() ([]byte, error) { 351 if m == nil { 352 return nil, nil 353 } 354 return swag.WriteJSON(m) 355 } 356 357 // UnmarshalBinary interface implementation 358 func (m *WritableAggregate) UnmarshalBinary(b []byte) error { 359 var res WritableAggregate 360 if err := swag.ReadJSON(b, &res); err != nil { 361 return err 362 } 363 *m = res 364 return nil 365 }