github.com/digitalocean/go-netbox@v0.0.2/netbox/models/device_type.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 // DeviceType device type 35 // 36 // swagger:model DeviceType 37 type DeviceType struct { 38 39 // Comments 40 Comments string `json:"comments,omitempty"` 41 42 // Created 43 // Read Only: true 44 // Format: date 45 Created strfmt.Date `json:"created,omitempty"` 46 47 // Custom fields 48 CustomFields interface{} `json:"custom_fields,omitempty"` 49 50 // Device count 51 // Read Only: true 52 DeviceCount int64 `json:"device_count,omitempty"` 53 54 // Display 55 // Read Only: true 56 Display string `json:"display,omitempty"` 57 58 // Display name 59 // Read Only: true 60 DisplayName string `json:"display_name,omitempty"` 61 62 // Front image 63 // Read Only: true 64 // Format: uri 65 FrontImage strfmt.URI `json:"front_image,omitempty"` 66 67 // Id 68 // Read Only: true 69 ID int64 `json:"id,omitempty"` 70 71 // Is full depth 72 // 73 // Device consumes both front and rear rack faces 74 IsFullDepth bool `json:"is_full_depth,omitempty"` 75 76 // Last updated 77 // Read Only: true 78 // Format: date-time 79 LastUpdated strfmt.DateTime `json:"last_updated,omitempty"` 80 81 // manufacturer 82 // Required: true 83 Manufacturer *NestedManufacturer `json:"manufacturer"` 84 85 // Model 86 // Required: true 87 // Max Length: 100 88 // Min Length: 1 89 Model *string `json:"model"` 90 91 // Part number 92 // 93 // Discrete part number (optional) 94 // Max Length: 50 95 PartNumber string `json:"part_number,omitempty"` 96 97 // Rear image 98 // Read Only: true 99 // Format: uri 100 RearImage strfmt.URI `json:"rear_image,omitempty"` 101 102 // Slug 103 // Required: true 104 // Max Length: 100 105 // Min Length: 1 106 // Pattern: ^[-a-zA-Z0-9_]+$ 107 Slug *string `json:"slug"` 108 109 // subdevice role 110 SubdeviceRole *DeviceTypeSubdeviceRole `json:"subdevice_role,omitempty"` 111 112 // tags 113 Tags []*NestedTag `json:"tags"` 114 115 // Height (U) 116 // Maximum: 32767 117 // Minimum: 0 118 UHeight *int64 `json:"u_height,omitempty"` 119 120 // Url 121 // Read Only: true 122 // Format: uri 123 URL strfmt.URI `json:"url,omitempty"` 124 } 125 126 // Validate validates this device type 127 func (m *DeviceType) Validate(formats strfmt.Registry) error { 128 var res []error 129 130 if err := m.validateCreated(formats); err != nil { 131 res = append(res, err) 132 } 133 134 if err := m.validateFrontImage(formats); err != nil { 135 res = append(res, err) 136 } 137 138 if err := m.validateLastUpdated(formats); err != nil { 139 res = append(res, err) 140 } 141 142 if err := m.validateManufacturer(formats); err != nil { 143 res = append(res, err) 144 } 145 146 if err := m.validateModel(formats); err != nil { 147 res = append(res, err) 148 } 149 150 if err := m.validatePartNumber(formats); err != nil { 151 res = append(res, err) 152 } 153 154 if err := m.validateRearImage(formats); err != nil { 155 res = append(res, err) 156 } 157 158 if err := m.validateSlug(formats); err != nil { 159 res = append(res, err) 160 } 161 162 if err := m.validateSubdeviceRole(formats); err != nil { 163 res = append(res, err) 164 } 165 166 if err := m.validateTags(formats); err != nil { 167 res = append(res, err) 168 } 169 170 if err := m.validateUHeight(formats); err != nil { 171 res = append(res, err) 172 } 173 174 if err := m.validateURL(formats); err != nil { 175 res = append(res, err) 176 } 177 178 if len(res) > 0 { 179 return errors.CompositeValidationError(res...) 180 } 181 return nil 182 } 183 184 func (m *DeviceType) validateCreated(formats strfmt.Registry) error { 185 if swag.IsZero(m.Created) { // not required 186 return nil 187 } 188 189 if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil { 190 return err 191 } 192 193 return nil 194 } 195 196 func (m *DeviceType) validateFrontImage(formats strfmt.Registry) error { 197 if swag.IsZero(m.FrontImage) { // not required 198 return nil 199 } 200 201 if err := validate.FormatOf("front_image", "body", "uri", m.FrontImage.String(), formats); err != nil { 202 return err 203 } 204 205 return nil 206 } 207 208 func (m *DeviceType) validateLastUpdated(formats strfmt.Registry) error { 209 if swag.IsZero(m.LastUpdated) { // not required 210 return nil 211 } 212 213 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 214 return err 215 } 216 217 return nil 218 } 219 220 func (m *DeviceType) validateManufacturer(formats strfmt.Registry) error { 221 222 if err := validate.Required("manufacturer", "body", m.Manufacturer); err != nil { 223 return err 224 } 225 226 if m.Manufacturer != nil { 227 if err := m.Manufacturer.Validate(formats); err != nil { 228 if ve, ok := err.(*errors.Validation); ok { 229 return ve.ValidateName("manufacturer") 230 } else if ce, ok := err.(*errors.CompositeError); ok { 231 return ce.ValidateName("manufacturer") 232 } 233 return err 234 } 235 } 236 237 return nil 238 } 239 240 func (m *DeviceType) validateModel(formats strfmt.Registry) error { 241 242 if err := validate.Required("model", "body", m.Model); err != nil { 243 return err 244 } 245 246 if err := validate.MinLength("model", "body", *m.Model, 1); err != nil { 247 return err 248 } 249 250 if err := validate.MaxLength("model", "body", *m.Model, 100); err != nil { 251 return err 252 } 253 254 return nil 255 } 256 257 func (m *DeviceType) validatePartNumber(formats strfmt.Registry) error { 258 if swag.IsZero(m.PartNumber) { // not required 259 return nil 260 } 261 262 if err := validate.MaxLength("part_number", "body", m.PartNumber, 50); err != nil { 263 return err 264 } 265 266 return nil 267 } 268 269 func (m *DeviceType) validateRearImage(formats strfmt.Registry) error { 270 if swag.IsZero(m.RearImage) { // not required 271 return nil 272 } 273 274 if err := validate.FormatOf("rear_image", "body", "uri", m.RearImage.String(), formats); err != nil { 275 return err 276 } 277 278 return nil 279 } 280 281 func (m *DeviceType) validateSlug(formats strfmt.Registry) error { 282 283 if err := validate.Required("slug", "body", m.Slug); err != nil { 284 return err 285 } 286 287 if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil { 288 return err 289 } 290 291 if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil { 292 return err 293 } 294 295 if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil { 296 return err 297 } 298 299 return nil 300 } 301 302 func (m *DeviceType) validateSubdeviceRole(formats strfmt.Registry) error { 303 if swag.IsZero(m.SubdeviceRole) { // not required 304 return nil 305 } 306 307 if m.SubdeviceRole != nil { 308 if err := m.SubdeviceRole.Validate(formats); err != nil { 309 if ve, ok := err.(*errors.Validation); ok { 310 return ve.ValidateName("subdevice_role") 311 } else if ce, ok := err.(*errors.CompositeError); ok { 312 return ce.ValidateName("subdevice_role") 313 } 314 return err 315 } 316 } 317 318 return nil 319 } 320 321 func (m *DeviceType) validateTags(formats strfmt.Registry) error { 322 if swag.IsZero(m.Tags) { // not required 323 return nil 324 } 325 326 for i := 0; i < len(m.Tags); i++ { 327 if swag.IsZero(m.Tags[i]) { // not required 328 continue 329 } 330 331 if m.Tags[i] != nil { 332 if err := m.Tags[i].Validate(formats); err != nil { 333 if ve, ok := err.(*errors.Validation); ok { 334 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 335 } else if ce, ok := err.(*errors.CompositeError); ok { 336 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 337 } 338 return err 339 } 340 } 341 342 } 343 344 return nil 345 } 346 347 func (m *DeviceType) validateUHeight(formats strfmt.Registry) error { 348 if swag.IsZero(m.UHeight) { // not required 349 return nil 350 } 351 352 if err := validate.MinimumInt("u_height", "body", *m.UHeight, 0, false); err != nil { 353 return err 354 } 355 356 if err := validate.MaximumInt("u_height", "body", *m.UHeight, 32767, false); err != nil { 357 return err 358 } 359 360 return nil 361 } 362 363 func (m *DeviceType) validateURL(formats strfmt.Registry) error { 364 if swag.IsZero(m.URL) { // not required 365 return nil 366 } 367 368 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 369 return err 370 } 371 372 return nil 373 } 374 375 // ContextValidate validate this device type based on the context it is used 376 func (m *DeviceType) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 377 var res []error 378 379 if err := m.contextValidateCreated(ctx, formats); err != nil { 380 res = append(res, err) 381 } 382 383 if err := m.contextValidateDeviceCount(ctx, formats); err != nil { 384 res = append(res, err) 385 } 386 387 if err := m.contextValidateDisplay(ctx, formats); err != nil { 388 res = append(res, err) 389 } 390 391 if err := m.contextValidateDisplayName(ctx, formats); err != nil { 392 res = append(res, err) 393 } 394 395 if err := m.contextValidateFrontImage(ctx, formats); err != nil { 396 res = append(res, err) 397 } 398 399 if err := m.contextValidateID(ctx, formats); err != nil { 400 res = append(res, err) 401 } 402 403 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 404 res = append(res, err) 405 } 406 407 if err := m.contextValidateManufacturer(ctx, formats); err != nil { 408 res = append(res, err) 409 } 410 411 if err := m.contextValidateRearImage(ctx, formats); err != nil { 412 res = append(res, err) 413 } 414 415 if err := m.contextValidateSubdeviceRole(ctx, formats); err != nil { 416 res = append(res, err) 417 } 418 419 if err := m.contextValidateTags(ctx, formats); err != nil { 420 res = append(res, err) 421 } 422 423 if err := m.contextValidateURL(ctx, formats); err != nil { 424 res = append(res, err) 425 } 426 427 if len(res) > 0 { 428 return errors.CompositeValidationError(res...) 429 } 430 return nil 431 } 432 433 func (m *DeviceType) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error { 434 435 if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil { 436 return err 437 } 438 439 return nil 440 } 441 442 func (m *DeviceType) contextValidateDeviceCount(ctx context.Context, formats strfmt.Registry) error { 443 444 if err := validate.ReadOnly(ctx, "device_count", "body", int64(m.DeviceCount)); err != nil { 445 return err 446 } 447 448 return nil 449 } 450 451 func (m *DeviceType) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 452 453 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 454 return err 455 } 456 457 return nil 458 } 459 460 func (m *DeviceType) contextValidateDisplayName(ctx context.Context, formats strfmt.Registry) error { 461 462 if err := validate.ReadOnly(ctx, "display_name", "body", string(m.DisplayName)); err != nil { 463 return err 464 } 465 466 return nil 467 } 468 469 func (m *DeviceType) contextValidateFrontImage(ctx context.Context, formats strfmt.Registry) error { 470 471 if err := validate.ReadOnly(ctx, "front_image", "body", strfmt.URI(m.FrontImage)); err != nil { 472 return err 473 } 474 475 return nil 476 } 477 478 func (m *DeviceType) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 479 480 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 481 return err 482 } 483 484 return nil 485 } 486 487 func (m *DeviceType) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 488 489 if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 490 return err 491 } 492 493 return nil 494 } 495 496 func (m *DeviceType) contextValidateManufacturer(ctx context.Context, formats strfmt.Registry) error { 497 498 if m.Manufacturer != nil { 499 if err := m.Manufacturer.ContextValidate(ctx, formats); err != nil { 500 if ve, ok := err.(*errors.Validation); ok { 501 return ve.ValidateName("manufacturer") 502 } else if ce, ok := err.(*errors.CompositeError); ok { 503 return ce.ValidateName("manufacturer") 504 } 505 return err 506 } 507 } 508 509 return nil 510 } 511 512 func (m *DeviceType) contextValidateRearImage(ctx context.Context, formats strfmt.Registry) error { 513 514 if err := validate.ReadOnly(ctx, "rear_image", "body", strfmt.URI(m.RearImage)); err != nil { 515 return err 516 } 517 518 return nil 519 } 520 521 func (m *DeviceType) contextValidateSubdeviceRole(ctx context.Context, formats strfmt.Registry) error { 522 523 if m.SubdeviceRole != nil { 524 if err := m.SubdeviceRole.ContextValidate(ctx, formats); err != nil { 525 if ve, ok := err.(*errors.Validation); ok { 526 return ve.ValidateName("subdevice_role") 527 } else if ce, ok := err.(*errors.CompositeError); ok { 528 return ce.ValidateName("subdevice_role") 529 } 530 return err 531 } 532 } 533 534 return nil 535 } 536 537 func (m *DeviceType) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 538 539 for i := 0; i < len(m.Tags); i++ { 540 541 if m.Tags[i] != nil { 542 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 543 if ve, ok := err.(*errors.Validation); ok { 544 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 545 } else if ce, ok := err.(*errors.CompositeError); ok { 546 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 547 } 548 return err 549 } 550 } 551 552 } 553 554 return nil 555 } 556 557 func (m *DeviceType) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 558 559 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 560 return err 561 } 562 563 return nil 564 } 565 566 // MarshalBinary interface implementation 567 func (m *DeviceType) MarshalBinary() ([]byte, error) { 568 if m == nil { 569 return nil, nil 570 } 571 return swag.WriteJSON(m) 572 } 573 574 // UnmarshalBinary interface implementation 575 func (m *DeviceType) UnmarshalBinary(b []byte) error { 576 var res DeviceType 577 if err := swag.ReadJSON(b, &res); err != nil { 578 return err 579 } 580 *m = res 581 return nil 582 } 583 584 // DeviceTypeSubdeviceRole Subdevice role 585 // 586 // swagger:model DeviceTypeSubdeviceRole 587 type DeviceTypeSubdeviceRole struct { 588 589 // label 590 // Required: true 591 // Enum: [Parent Child] 592 Label *string `json:"label"` 593 594 // value 595 // Required: true 596 // Enum: [parent child] 597 Value *string `json:"value"` 598 } 599 600 // Validate validates this device type subdevice role 601 func (m *DeviceTypeSubdeviceRole) Validate(formats strfmt.Registry) error { 602 var res []error 603 604 if err := m.validateLabel(formats); err != nil { 605 res = append(res, err) 606 } 607 608 if err := m.validateValue(formats); err != nil { 609 res = append(res, err) 610 } 611 612 if len(res) > 0 { 613 return errors.CompositeValidationError(res...) 614 } 615 return nil 616 } 617 618 var deviceTypeSubdeviceRoleTypeLabelPropEnum []interface{} 619 620 func init() { 621 var res []string 622 if err := json.Unmarshal([]byte(`["Parent","Child"]`), &res); err != nil { 623 panic(err) 624 } 625 for _, v := range res { 626 deviceTypeSubdeviceRoleTypeLabelPropEnum = append(deviceTypeSubdeviceRoleTypeLabelPropEnum, v) 627 } 628 } 629 630 const ( 631 632 // DeviceTypeSubdeviceRoleLabelParent captures enum value "Parent" 633 DeviceTypeSubdeviceRoleLabelParent string = "Parent" 634 635 // DeviceTypeSubdeviceRoleLabelChild captures enum value "Child" 636 DeviceTypeSubdeviceRoleLabelChild string = "Child" 637 ) 638 639 // prop value enum 640 func (m *DeviceTypeSubdeviceRole) validateLabelEnum(path, location string, value string) error { 641 if err := validate.EnumCase(path, location, value, deviceTypeSubdeviceRoleTypeLabelPropEnum, true); err != nil { 642 return err 643 } 644 return nil 645 } 646 647 func (m *DeviceTypeSubdeviceRole) validateLabel(formats strfmt.Registry) error { 648 649 if err := validate.Required("subdevice_role"+"."+"label", "body", m.Label); err != nil { 650 return err 651 } 652 653 // value enum 654 if err := m.validateLabelEnum("subdevice_role"+"."+"label", "body", *m.Label); err != nil { 655 return err 656 } 657 658 return nil 659 } 660 661 var deviceTypeSubdeviceRoleTypeValuePropEnum []interface{} 662 663 func init() { 664 var res []string 665 if err := json.Unmarshal([]byte(`["parent","child"]`), &res); err != nil { 666 panic(err) 667 } 668 for _, v := range res { 669 deviceTypeSubdeviceRoleTypeValuePropEnum = append(deviceTypeSubdeviceRoleTypeValuePropEnum, v) 670 } 671 } 672 673 const ( 674 675 // DeviceTypeSubdeviceRoleValueParent captures enum value "parent" 676 DeviceTypeSubdeviceRoleValueParent string = "parent" 677 678 // DeviceTypeSubdeviceRoleValueChild captures enum value "child" 679 DeviceTypeSubdeviceRoleValueChild string = "child" 680 ) 681 682 // prop value enum 683 func (m *DeviceTypeSubdeviceRole) validateValueEnum(path, location string, value string) error { 684 if err := validate.EnumCase(path, location, value, deviceTypeSubdeviceRoleTypeValuePropEnum, true); err != nil { 685 return err 686 } 687 return nil 688 } 689 690 func (m *DeviceTypeSubdeviceRole) validateValue(formats strfmt.Registry) error { 691 692 if err := validate.Required("subdevice_role"+"."+"value", "body", m.Value); err != nil { 693 return err 694 } 695 696 // value enum 697 if err := m.validateValueEnum("subdevice_role"+"."+"value", "body", *m.Value); err != nil { 698 return err 699 } 700 701 return nil 702 } 703 704 // ContextValidate validates this device type subdevice role based on context it is used 705 func (m *DeviceTypeSubdeviceRole) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 706 return nil 707 } 708 709 // MarshalBinary interface implementation 710 func (m *DeviceTypeSubdeviceRole) MarshalBinary() ([]byte, error) { 711 if m == nil { 712 return nil, nil 713 } 714 return swag.WriteJSON(m) 715 } 716 717 // UnmarshalBinary interface implementation 718 func (m *DeviceTypeSubdeviceRole) UnmarshalBinary(b []byte) error { 719 var res DeviceTypeSubdeviceRole 720 if err := swag.ReadJSON(b, &res); err != nil { 721 return err 722 } 723 *m = res 724 return nil 725 }