github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_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 // WritableDeviceType writable device type 35 // 36 // swagger:model WritableDeviceType 37 type WritableDeviceType 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 *int64 `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 // Parent/child status 110 // 111 // Parent devices house child devices in device bays. Leave blank if this device type is neither a parent nor a child. 112 // Enum: [parent child] 113 SubdeviceRole string `json:"subdevice_role,omitempty"` 114 115 // tags 116 Tags []*NestedTag `json:"tags"` 117 118 // Height (U) 119 // Maximum: 32767 120 // Minimum: 0 121 UHeight *int64 `json:"u_height,omitempty"` 122 123 // Url 124 // Read Only: true 125 // Format: uri 126 URL strfmt.URI `json:"url,omitempty"` 127 } 128 129 // Validate validates this writable device type 130 func (m *WritableDeviceType) Validate(formats strfmt.Registry) error { 131 var res []error 132 133 if err := m.validateCreated(formats); err != nil { 134 res = append(res, err) 135 } 136 137 if err := m.validateFrontImage(formats); err != nil { 138 res = append(res, err) 139 } 140 141 if err := m.validateLastUpdated(formats); err != nil { 142 res = append(res, err) 143 } 144 145 if err := m.validateManufacturer(formats); err != nil { 146 res = append(res, err) 147 } 148 149 if err := m.validateModel(formats); err != nil { 150 res = append(res, err) 151 } 152 153 if err := m.validatePartNumber(formats); err != nil { 154 res = append(res, err) 155 } 156 157 if err := m.validateRearImage(formats); err != nil { 158 res = append(res, err) 159 } 160 161 if err := m.validateSlug(formats); err != nil { 162 res = append(res, err) 163 } 164 165 if err := m.validateSubdeviceRole(formats); err != nil { 166 res = append(res, err) 167 } 168 169 if err := m.validateTags(formats); err != nil { 170 res = append(res, err) 171 } 172 173 if err := m.validateUHeight(formats); err != nil { 174 res = append(res, err) 175 } 176 177 if err := m.validateURL(formats); err != nil { 178 res = append(res, err) 179 } 180 181 if len(res) > 0 { 182 return errors.CompositeValidationError(res...) 183 } 184 return nil 185 } 186 187 func (m *WritableDeviceType) validateCreated(formats strfmt.Registry) error { 188 if swag.IsZero(m.Created) { // not required 189 return nil 190 } 191 192 if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil { 193 return err 194 } 195 196 return nil 197 } 198 199 func (m *WritableDeviceType) validateFrontImage(formats strfmt.Registry) error { 200 if swag.IsZero(m.FrontImage) { // not required 201 return nil 202 } 203 204 if err := validate.FormatOf("front_image", "body", "uri", m.FrontImage.String(), formats); err != nil { 205 return err 206 } 207 208 return nil 209 } 210 211 func (m *WritableDeviceType) validateLastUpdated(formats strfmt.Registry) error { 212 if swag.IsZero(m.LastUpdated) { // not required 213 return nil 214 } 215 216 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 217 return err 218 } 219 220 return nil 221 } 222 223 func (m *WritableDeviceType) validateManufacturer(formats strfmt.Registry) error { 224 225 if err := validate.Required("manufacturer", "body", m.Manufacturer); err != nil { 226 return err 227 } 228 229 return nil 230 } 231 232 func (m *WritableDeviceType) validateModel(formats strfmt.Registry) error { 233 234 if err := validate.Required("model", "body", m.Model); err != nil { 235 return err 236 } 237 238 if err := validate.MinLength("model", "body", *m.Model, 1); err != nil { 239 return err 240 } 241 242 if err := validate.MaxLength("model", "body", *m.Model, 100); err != nil { 243 return err 244 } 245 246 return nil 247 } 248 249 func (m *WritableDeviceType) validatePartNumber(formats strfmt.Registry) error { 250 if swag.IsZero(m.PartNumber) { // not required 251 return nil 252 } 253 254 if err := validate.MaxLength("part_number", "body", m.PartNumber, 50); err != nil { 255 return err 256 } 257 258 return nil 259 } 260 261 func (m *WritableDeviceType) validateRearImage(formats strfmt.Registry) error { 262 if swag.IsZero(m.RearImage) { // not required 263 return nil 264 } 265 266 if err := validate.FormatOf("rear_image", "body", "uri", m.RearImage.String(), formats); err != nil { 267 return err 268 } 269 270 return nil 271 } 272 273 func (m *WritableDeviceType) validateSlug(formats strfmt.Registry) error { 274 275 if err := validate.Required("slug", "body", m.Slug); err != nil { 276 return err 277 } 278 279 if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil { 280 return err 281 } 282 283 if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil { 284 return err 285 } 286 287 if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil { 288 return err 289 } 290 291 return nil 292 } 293 294 var writableDeviceTypeTypeSubdeviceRolePropEnum []interface{} 295 296 func init() { 297 var res []string 298 if err := json.Unmarshal([]byte(`["parent","child"]`), &res); err != nil { 299 panic(err) 300 } 301 for _, v := range res { 302 writableDeviceTypeTypeSubdeviceRolePropEnum = append(writableDeviceTypeTypeSubdeviceRolePropEnum, v) 303 } 304 } 305 306 const ( 307 308 // WritableDeviceTypeSubdeviceRoleParent captures enum value "parent" 309 WritableDeviceTypeSubdeviceRoleParent string = "parent" 310 311 // WritableDeviceTypeSubdeviceRoleChild captures enum value "child" 312 WritableDeviceTypeSubdeviceRoleChild string = "child" 313 ) 314 315 // prop value enum 316 func (m *WritableDeviceType) validateSubdeviceRoleEnum(path, location string, value string) error { 317 if err := validate.EnumCase(path, location, value, writableDeviceTypeTypeSubdeviceRolePropEnum, true); err != nil { 318 return err 319 } 320 return nil 321 } 322 323 func (m *WritableDeviceType) validateSubdeviceRole(formats strfmt.Registry) error { 324 if swag.IsZero(m.SubdeviceRole) { // not required 325 return nil 326 } 327 328 // value enum 329 if err := m.validateSubdeviceRoleEnum("subdevice_role", "body", m.SubdeviceRole); err != nil { 330 return err 331 } 332 333 return nil 334 } 335 336 func (m *WritableDeviceType) validateTags(formats strfmt.Registry) error { 337 if swag.IsZero(m.Tags) { // not required 338 return nil 339 } 340 341 for i := 0; i < len(m.Tags); i++ { 342 if swag.IsZero(m.Tags[i]) { // not required 343 continue 344 } 345 346 if m.Tags[i] != nil { 347 if err := m.Tags[i].Validate(formats); err != nil { 348 if ve, ok := err.(*errors.Validation); ok { 349 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 350 } else if ce, ok := err.(*errors.CompositeError); ok { 351 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 352 } 353 return err 354 } 355 } 356 357 } 358 359 return nil 360 } 361 362 func (m *WritableDeviceType) validateUHeight(formats strfmt.Registry) error { 363 if swag.IsZero(m.UHeight) { // not required 364 return nil 365 } 366 367 if err := validate.MinimumInt("u_height", "body", *m.UHeight, 0, false); err != nil { 368 return err 369 } 370 371 if err := validate.MaximumInt("u_height", "body", *m.UHeight, 32767, false); err != nil { 372 return err 373 } 374 375 return nil 376 } 377 378 func (m *WritableDeviceType) validateURL(formats strfmt.Registry) error { 379 if swag.IsZero(m.URL) { // not required 380 return nil 381 } 382 383 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 384 return err 385 } 386 387 return nil 388 } 389 390 // ContextValidate validate this writable device type based on the context it is used 391 func (m *WritableDeviceType) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 392 var res []error 393 394 if err := m.contextValidateCreated(ctx, formats); err != nil { 395 res = append(res, err) 396 } 397 398 if err := m.contextValidateDeviceCount(ctx, formats); err != nil { 399 res = append(res, err) 400 } 401 402 if err := m.contextValidateDisplay(ctx, formats); err != nil { 403 res = append(res, err) 404 } 405 406 if err := m.contextValidateDisplayName(ctx, formats); err != nil { 407 res = append(res, err) 408 } 409 410 if err := m.contextValidateFrontImage(ctx, formats); err != nil { 411 res = append(res, err) 412 } 413 414 if err := m.contextValidateID(ctx, formats); err != nil { 415 res = append(res, err) 416 } 417 418 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 419 res = append(res, err) 420 } 421 422 if err := m.contextValidateRearImage(ctx, formats); err != nil { 423 res = append(res, err) 424 } 425 426 if err := m.contextValidateTags(ctx, formats); err != nil { 427 res = append(res, err) 428 } 429 430 if err := m.contextValidateURL(ctx, formats); err != nil { 431 res = append(res, err) 432 } 433 434 if len(res) > 0 { 435 return errors.CompositeValidationError(res...) 436 } 437 return nil 438 } 439 440 func (m *WritableDeviceType) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error { 441 442 if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil { 443 return err 444 } 445 446 return nil 447 } 448 449 func (m *WritableDeviceType) contextValidateDeviceCount(ctx context.Context, formats strfmt.Registry) error { 450 451 if err := validate.ReadOnly(ctx, "device_count", "body", int64(m.DeviceCount)); err != nil { 452 return err 453 } 454 455 return nil 456 } 457 458 func (m *WritableDeviceType) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 459 460 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 461 return err 462 } 463 464 return nil 465 } 466 467 func (m *WritableDeviceType) contextValidateDisplayName(ctx context.Context, formats strfmt.Registry) error { 468 469 if err := validate.ReadOnly(ctx, "display_name", "body", string(m.DisplayName)); err != nil { 470 return err 471 } 472 473 return nil 474 } 475 476 func (m *WritableDeviceType) contextValidateFrontImage(ctx context.Context, formats strfmt.Registry) error { 477 478 if err := validate.ReadOnly(ctx, "front_image", "body", strfmt.URI(m.FrontImage)); err != nil { 479 return err 480 } 481 482 return nil 483 } 484 485 func (m *WritableDeviceType) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 486 487 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 488 return err 489 } 490 491 return nil 492 } 493 494 func (m *WritableDeviceType) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 495 496 if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 497 return err 498 } 499 500 return nil 501 } 502 503 func (m *WritableDeviceType) contextValidateRearImage(ctx context.Context, formats strfmt.Registry) error { 504 505 if err := validate.ReadOnly(ctx, "rear_image", "body", strfmt.URI(m.RearImage)); err != nil { 506 return err 507 } 508 509 return nil 510 } 511 512 func (m *WritableDeviceType) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 513 514 for i := 0; i < len(m.Tags); i++ { 515 516 if m.Tags[i] != nil { 517 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 518 if ve, ok := err.(*errors.Validation); ok { 519 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 520 } else if ce, ok := err.(*errors.CompositeError); ok { 521 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 522 } 523 return err 524 } 525 } 526 527 } 528 529 return nil 530 } 531 532 func (m *WritableDeviceType) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 533 534 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 535 return err 536 } 537 538 return nil 539 } 540 541 // MarshalBinary interface implementation 542 func (m *WritableDeviceType) MarshalBinary() ([]byte, error) { 543 if m == nil { 544 return nil, nil 545 } 546 return swag.WriteJSON(m) 547 } 548 549 // UnmarshalBinary interface implementation 550 func (m *WritableDeviceType) UnmarshalBinary(b []byte) error { 551 var res WritableDeviceType 552 if err := swag.ReadJSON(b, &res); err != nil { 553 return err 554 } 555 *m = res 556 return nil 557 }