github.com/digitalocean/go-netbox@v0.0.2/netbox/models/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 "encoding/json" 26 "strconv" 27 28 "github.com/go-openapi/errors" 29 "github.com/go-openapi/strfmt" 30 "github.com/go-openapi/swag" 31 "github.com/go-openapi/validate" 32 ) 33 34 // Aggregate aggregate 35 // 36 // swagger:model Aggregate 37 type Aggregate struct { 38 39 // Created 40 // Read Only: true 41 // Format: date 42 Created strfmt.Date `json:"created,omitempty"` 43 44 // Custom fields 45 CustomFields interface{} `json:"custom_fields,omitempty"` 46 47 // Date added 48 // Format: date 49 DateAdded *strfmt.Date `json:"date_added,omitempty"` 50 51 // Description 52 // Max Length: 200 53 Description string `json:"description,omitempty"` 54 55 // Display 56 // Read Only: true 57 Display string `json:"display,omitempty"` 58 59 // family 60 Family *AggregateFamily `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 *NestedRIR `json:"rir"` 78 79 // tags 80 Tags []*NestedTag `json:"tags"` 81 82 // tenant 83 Tenant *NestedTenant `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 aggregate 92 func (m *Aggregate) 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.validateFamily(formats); err != nil { 108 res = append(res, err) 109 } 110 111 if err := m.validateLastUpdated(formats); err != nil { 112 res = append(res, err) 113 } 114 115 if err := m.validatePrefix(formats); err != nil { 116 res = append(res, err) 117 } 118 119 if err := m.validateRir(formats); err != nil { 120 res = append(res, err) 121 } 122 123 if err := m.validateTags(formats); err != nil { 124 res = append(res, err) 125 } 126 127 if err := m.validateTenant(formats); err != nil { 128 res = append(res, err) 129 } 130 131 if err := m.validateURL(formats); err != nil { 132 res = append(res, err) 133 } 134 135 if len(res) > 0 { 136 return errors.CompositeValidationError(res...) 137 } 138 return nil 139 } 140 141 func (m *Aggregate) validateCreated(formats strfmt.Registry) error { 142 if swag.IsZero(m.Created) { // not required 143 return nil 144 } 145 146 if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil { 147 return err 148 } 149 150 return nil 151 } 152 153 func (m *Aggregate) validateDateAdded(formats strfmt.Registry) error { 154 if swag.IsZero(m.DateAdded) { // not required 155 return nil 156 } 157 158 if err := validate.FormatOf("date_added", "body", "date", m.DateAdded.String(), formats); err != nil { 159 return err 160 } 161 162 return nil 163 } 164 165 func (m *Aggregate) validateDescription(formats strfmt.Registry) error { 166 if swag.IsZero(m.Description) { // not required 167 return nil 168 } 169 170 if err := validate.MaxLength("description", "body", m.Description, 200); err != nil { 171 return err 172 } 173 174 return nil 175 } 176 177 func (m *Aggregate) validateFamily(formats strfmt.Registry) error { 178 if swag.IsZero(m.Family) { // not required 179 return nil 180 } 181 182 if m.Family != nil { 183 if err := m.Family.Validate(formats); err != nil { 184 if ve, ok := err.(*errors.Validation); ok { 185 return ve.ValidateName("family") 186 } else if ce, ok := err.(*errors.CompositeError); ok { 187 return ce.ValidateName("family") 188 } 189 return err 190 } 191 } 192 193 return nil 194 } 195 196 func (m *Aggregate) validateLastUpdated(formats strfmt.Registry) error { 197 if swag.IsZero(m.LastUpdated) { // not required 198 return nil 199 } 200 201 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 202 return err 203 } 204 205 return nil 206 } 207 208 func (m *Aggregate) validatePrefix(formats strfmt.Registry) error { 209 210 if err := validate.Required("prefix", "body", m.Prefix); err != nil { 211 return err 212 } 213 214 return nil 215 } 216 217 func (m *Aggregate) validateRir(formats strfmt.Registry) error { 218 219 if err := validate.Required("rir", "body", m.Rir); err != nil { 220 return err 221 } 222 223 if m.Rir != nil { 224 if err := m.Rir.Validate(formats); err != nil { 225 if ve, ok := err.(*errors.Validation); ok { 226 return ve.ValidateName("rir") 227 } else if ce, ok := err.(*errors.CompositeError); ok { 228 return ce.ValidateName("rir") 229 } 230 return err 231 } 232 } 233 234 return nil 235 } 236 237 func (m *Aggregate) validateTags(formats strfmt.Registry) error { 238 if swag.IsZero(m.Tags) { // not required 239 return nil 240 } 241 242 for i := 0; i < len(m.Tags); i++ { 243 if swag.IsZero(m.Tags[i]) { // not required 244 continue 245 } 246 247 if m.Tags[i] != nil { 248 if err := m.Tags[i].Validate(formats); err != nil { 249 if ve, ok := err.(*errors.Validation); ok { 250 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 251 } else if ce, ok := err.(*errors.CompositeError); ok { 252 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 253 } 254 return err 255 } 256 } 257 258 } 259 260 return nil 261 } 262 263 func (m *Aggregate) validateTenant(formats strfmt.Registry) error { 264 if swag.IsZero(m.Tenant) { // not required 265 return nil 266 } 267 268 if m.Tenant != nil { 269 if err := m.Tenant.Validate(formats); err != nil { 270 if ve, ok := err.(*errors.Validation); ok { 271 return ve.ValidateName("tenant") 272 } else if ce, ok := err.(*errors.CompositeError); ok { 273 return ce.ValidateName("tenant") 274 } 275 return err 276 } 277 } 278 279 return nil 280 } 281 282 func (m *Aggregate) validateURL(formats strfmt.Registry) error { 283 if swag.IsZero(m.URL) { // not required 284 return nil 285 } 286 287 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 288 return err 289 } 290 291 return nil 292 } 293 294 // ContextValidate validate this aggregate based on the context it is used 295 func (m *Aggregate) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 296 var res []error 297 298 if err := m.contextValidateCreated(ctx, formats); err != nil { 299 res = append(res, err) 300 } 301 302 if err := m.contextValidateDisplay(ctx, formats); err != nil { 303 res = append(res, err) 304 } 305 306 if err := m.contextValidateFamily(ctx, formats); err != nil { 307 res = append(res, err) 308 } 309 310 if err := m.contextValidateID(ctx, formats); err != nil { 311 res = append(res, err) 312 } 313 314 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 315 res = append(res, err) 316 } 317 318 if err := m.contextValidateRir(ctx, formats); err != nil { 319 res = append(res, err) 320 } 321 322 if err := m.contextValidateTags(ctx, formats); err != nil { 323 res = append(res, err) 324 } 325 326 if err := m.contextValidateTenant(ctx, formats); err != nil { 327 res = append(res, err) 328 } 329 330 if err := m.contextValidateURL(ctx, formats); err != nil { 331 res = append(res, err) 332 } 333 334 if len(res) > 0 { 335 return errors.CompositeValidationError(res...) 336 } 337 return nil 338 } 339 340 func (m *Aggregate) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error { 341 342 if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil { 343 return err 344 } 345 346 return nil 347 } 348 349 func (m *Aggregate) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 350 351 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 352 return err 353 } 354 355 return nil 356 } 357 358 func (m *Aggregate) contextValidateFamily(ctx context.Context, formats strfmt.Registry) error { 359 360 if m.Family != nil { 361 if err := m.Family.ContextValidate(ctx, formats); err != nil { 362 if ve, ok := err.(*errors.Validation); ok { 363 return ve.ValidateName("family") 364 } else if ce, ok := err.(*errors.CompositeError); ok { 365 return ce.ValidateName("family") 366 } 367 return err 368 } 369 } 370 371 return nil 372 } 373 374 func (m *Aggregate) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 375 376 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 377 return err 378 } 379 380 return nil 381 } 382 383 func (m *Aggregate) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 384 385 if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 386 return err 387 } 388 389 return nil 390 } 391 392 func (m *Aggregate) contextValidateRir(ctx context.Context, formats strfmt.Registry) error { 393 394 if m.Rir != nil { 395 if err := m.Rir.ContextValidate(ctx, formats); err != nil { 396 if ve, ok := err.(*errors.Validation); ok { 397 return ve.ValidateName("rir") 398 } else if ce, ok := err.(*errors.CompositeError); ok { 399 return ce.ValidateName("rir") 400 } 401 return err 402 } 403 } 404 405 return nil 406 } 407 408 func (m *Aggregate) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 409 410 for i := 0; i < len(m.Tags); i++ { 411 412 if m.Tags[i] != nil { 413 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 414 if ve, ok := err.(*errors.Validation); ok { 415 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 416 } else if ce, ok := err.(*errors.CompositeError); ok { 417 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 418 } 419 return err 420 } 421 } 422 423 } 424 425 return nil 426 } 427 428 func (m *Aggregate) contextValidateTenant(ctx context.Context, formats strfmt.Registry) error { 429 430 if m.Tenant != nil { 431 if err := m.Tenant.ContextValidate(ctx, formats); err != nil { 432 if ve, ok := err.(*errors.Validation); ok { 433 return ve.ValidateName("tenant") 434 } else if ce, ok := err.(*errors.CompositeError); ok { 435 return ce.ValidateName("tenant") 436 } 437 return err 438 } 439 } 440 441 return nil 442 } 443 444 func (m *Aggregate) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 445 446 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 447 return err 448 } 449 450 return nil 451 } 452 453 // MarshalBinary interface implementation 454 func (m *Aggregate) MarshalBinary() ([]byte, error) { 455 if m == nil { 456 return nil, nil 457 } 458 return swag.WriteJSON(m) 459 } 460 461 // UnmarshalBinary interface implementation 462 func (m *Aggregate) UnmarshalBinary(b []byte) error { 463 var res Aggregate 464 if err := swag.ReadJSON(b, &res); err != nil { 465 return err 466 } 467 *m = res 468 return nil 469 } 470 471 // AggregateFamily Family 472 // 473 // swagger:model AggregateFamily 474 type AggregateFamily struct { 475 476 // label 477 // Required: true 478 // Enum: [IPv4 IPv6] 479 Label *string `json:"label"` 480 481 // value 482 // Required: true 483 // Enum: [4 6] 484 Value *int64 `json:"value"` 485 } 486 487 // Validate validates this aggregate family 488 func (m *AggregateFamily) Validate(formats strfmt.Registry) error { 489 var res []error 490 491 if err := m.validateLabel(formats); err != nil { 492 res = append(res, err) 493 } 494 495 if err := m.validateValue(formats); err != nil { 496 res = append(res, err) 497 } 498 499 if len(res) > 0 { 500 return errors.CompositeValidationError(res...) 501 } 502 return nil 503 } 504 505 var aggregateFamilyTypeLabelPropEnum []interface{} 506 507 func init() { 508 var res []string 509 if err := json.Unmarshal([]byte(`["IPv4","IPv6"]`), &res); err != nil { 510 panic(err) 511 } 512 for _, v := range res { 513 aggregateFamilyTypeLabelPropEnum = append(aggregateFamilyTypeLabelPropEnum, v) 514 } 515 } 516 517 const ( 518 519 // AggregateFamilyLabelIPV4 captures enum value "IPv4" 520 AggregateFamilyLabelIPV4 string = "IPv4" 521 522 // AggregateFamilyLabelIPV6 captures enum value "IPv6" 523 AggregateFamilyLabelIPV6 string = "IPv6" 524 ) 525 526 // prop value enum 527 func (m *AggregateFamily) validateLabelEnum(path, location string, value string) error { 528 if err := validate.EnumCase(path, location, value, aggregateFamilyTypeLabelPropEnum, true); err != nil { 529 return err 530 } 531 return nil 532 } 533 534 func (m *AggregateFamily) validateLabel(formats strfmt.Registry) error { 535 536 if err := validate.Required("family"+"."+"label", "body", m.Label); err != nil { 537 return err 538 } 539 540 // value enum 541 if err := m.validateLabelEnum("family"+"."+"label", "body", *m.Label); err != nil { 542 return err 543 } 544 545 return nil 546 } 547 548 var aggregateFamilyTypeValuePropEnum []interface{} 549 550 func init() { 551 var res []int64 552 if err := json.Unmarshal([]byte(`[4,6]`), &res); err != nil { 553 panic(err) 554 } 555 for _, v := range res { 556 aggregateFamilyTypeValuePropEnum = append(aggregateFamilyTypeValuePropEnum, v) 557 } 558 } 559 560 // prop value enum 561 func (m *AggregateFamily) validateValueEnum(path, location string, value int64) error { 562 if err := validate.EnumCase(path, location, value, aggregateFamilyTypeValuePropEnum, true); err != nil { 563 return err 564 } 565 return nil 566 } 567 568 func (m *AggregateFamily) validateValue(formats strfmt.Registry) error { 569 570 if err := validate.Required("family"+"."+"value", "body", m.Value); err != nil { 571 return err 572 } 573 574 // value enum 575 if err := m.validateValueEnum("family"+"."+"value", "body", *m.Value); err != nil { 576 return err 577 } 578 579 return nil 580 } 581 582 // ContextValidate validate this aggregate family based on the context it is used 583 func (m *AggregateFamily) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 584 var res []error 585 586 if len(res) > 0 { 587 return errors.CompositeValidationError(res...) 588 } 589 return nil 590 } 591 592 // MarshalBinary interface implementation 593 func (m *AggregateFamily) MarshalBinary() ([]byte, error) { 594 if m == nil { 595 return nil, nil 596 } 597 return swag.WriteJSON(m) 598 } 599 600 // UnmarshalBinary interface implementation 601 func (m *AggregateFamily) UnmarshalBinary(b []byte) error { 602 var res AggregateFamily 603 if err := swag.ReadJSON(b, &res); err != nil { 604 return err 605 } 606 *m = res 607 return nil 608 }