github.com/digitalocean/go-netbox@v0.0.2/netbox/models/device_bay.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 // DeviceBay device bay 34 // 35 // swagger:model DeviceBay 36 type DeviceBay 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 // Description 47 // Max Length: 200 48 Description string `json:"description,omitempty"` 49 50 // device 51 // Required: true 52 Device *NestedDevice `json:"device"` 53 54 // Display 55 // Read Only: true 56 Display string `json:"display,omitempty"` 57 58 // Id 59 // Read Only: true 60 ID int64 `json:"id,omitempty"` 61 62 // installed device 63 InstalledDevice *NestedDevice `json:"installed_device,omitempty"` 64 65 // Label 66 // 67 // Physical label 68 // Max Length: 64 69 Label string `json:"label,omitempty"` 70 71 // Last updated 72 // Read Only: true 73 // Format: date-time 74 LastUpdated strfmt.DateTime `json:"last_updated,omitempty"` 75 76 // Name 77 // Required: true 78 // Max Length: 64 79 // Min Length: 1 80 Name *string `json:"name"` 81 82 // tags 83 Tags []*NestedTag `json:"tags"` 84 85 // Url 86 // Read Only: true 87 // Format: uri 88 URL strfmt.URI `json:"url,omitempty"` 89 } 90 91 // Validate validates this device bay 92 func (m *DeviceBay) 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.validateDescription(formats); err != nil { 100 res = append(res, err) 101 } 102 103 if err := m.validateDevice(formats); err != nil { 104 res = append(res, err) 105 } 106 107 if err := m.validateInstalledDevice(formats); err != nil { 108 res = append(res, err) 109 } 110 111 if err := m.validateLabel(formats); err != nil { 112 res = append(res, err) 113 } 114 115 if err := m.validateLastUpdated(formats); err != nil { 116 res = append(res, err) 117 } 118 119 if err := m.validateName(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.validateURL(formats); err != nil { 128 res = append(res, err) 129 } 130 131 if len(res) > 0 { 132 return errors.CompositeValidationError(res...) 133 } 134 return nil 135 } 136 137 func (m *DeviceBay) validateCreated(formats strfmt.Registry) error { 138 if swag.IsZero(m.Created) { // not required 139 return nil 140 } 141 142 if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil { 143 return err 144 } 145 146 return nil 147 } 148 149 func (m *DeviceBay) validateDescription(formats strfmt.Registry) error { 150 if swag.IsZero(m.Description) { // not required 151 return nil 152 } 153 154 if err := validate.MaxLength("description", "body", m.Description, 200); err != nil { 155 return err 156 } 157 158 return nil 159 } 160 161 func (m *DeviceBay) validateDevice(formats strfmt.Registry) error { 162 163 if err := validate.Required("device", "body", m.Device); err != nil { 164 return err 165 } 166 167 if m.Device != nil { 168 if err := m.Device.Validate(formats); err != nil { 169 if ve, ok := err.(*errors.Validation); ok { 170 return ve.ValidateName("device") 171 } else if ce, ok := err.(*errors.CompositeError); ok { 172 return ce.ValidateName("device") 173 } 174 return err 175 } 176 } 177 178 return nil 179 } 180 181 func (m *DeviceBay) validateInstalledDevice(formats strfmt.Registry) error { 182 if swag.IsZero(m.InstalledDevice) { // not required 183 return nil 184 } 185 186 if m.InstalledDevice != nil { 187 if err := m.InstalledDevice.Validate(formats); err != nil { 188 if ve, ok := err.(*errors.Validation); ok { 189 return ve.ValidateName("installed_device") 190 } else if ce, ok := err.(*errors.CompositeError); ok { 191 return ce.ValidateName("installed_device") 192 } 193 return err 194 } 195 } 196 197 return nil 198 } 199 200 func (m *DeviceBay) validateLabel(formats strfmt.Registry) error { 201 if swag.IsZero(m.Label) { // not required 202 return nil 203 } 204 205 if err := validate.MaxLength("label", "body", m.Label, 64); err != nil { 206 return err 207 } 208 209 return nil 210 } 211 212 func (m *DeviceBay) validateLastUpdated(formats strfmt.Registry) error { 213 if swag.IsZero(m.LastUpdated) { // not required 214 return nil 215 } 216 217 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 218 return err 219 } 220 221 return nil 222 } 223 224 func (m *DeviceBay) validateName(formats strfmt.Registry) error { 225 226 if err := validate.Required("name", "body", m.Name); err != nil { 227 return err 228 } 229 230 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 231 return err 232 } 233 234 if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil { 235 return err 236 } 237 238 return nil 239 } 240 241 func (m *DeviceBay) validateTags(formats strfmt.Registry) error { 242 if swag.IsZero(m.Tags) { // not required 243 return nil 244 } 245 246 for i := 0; i < len(m.Tags); i++ { 247 if swag.IsZero(m.Tags[i]) { // not required 248 continue 249 } 250 251 if m.Tags[i] != nil { 252 if err := m.Tags[i].Validate(formats); err != nil { 253 if ve, ok := err.(*errors.Validation); ok { 254 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 255 } else if ce, ok := err.(*errors.CompositeError); ok { 256 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 257 } 258 return err 259 } 260 } 261 262 } 263 264 return nil 265 } 266 267 func (m *DeviceBay) validateURL(formats strfmt.Registry) error { 268 if swag.IsZero(m.URL) { // not required 269 return nil 270 } 271 272 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 273 return err 274 } 275 276 return nil 277 } 278 279 // ContextValidate validate this device bay based on the context it is used 280 func (m *DeviceBay) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 281 var res []error 282 283 if err := m.contextValidateCreated(ctx, formats); err != nil { 284 res = append(res, err) 285 } 286 287 if err := m.contextValidateDevice(ctx, formats); err != nil { 288 res = append(res, err) 289 } 290 291 if err := m.contextValidateDisplay(ctx, formats); err != nil { 292 res = append(res, err) 293 } 294 295 if err := m.contextValidateID(ctx, formats); err != nil { 296 res = append(res, err) 297 } 298 299 if err := m.contextValidateInstalledDevice(ctx, formats); err != nil { 300 res = append(res, err) 301 } 302 303 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 304 res = append(res, err) 305 } 306 307 if err := m.contextValidateTags(ctx, formats); err != nil { 308 res = append(res, err) 309 } 310 311 if err := m.contextValidateURL(ctx, formats); err != nil { 312 res = append(res, err) 313 } 314 315 if len(res) > 0 { 316 return errors.CompositeValidationError(res...) 317 } 318 return nil 319 } 320 321 func (m *DeviceBay) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error { 322 323 if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil { 324 return err 325 } 326 327 return nil 328 } 329 330 func (m *DeviceBay) contextValidateDevice(ctx context.Context, formats strfmt.Registry) error { 331 332 if m.Device != nil { 333 if err := m.Device.ContextValidate(ctx, formats); err != nil { 334 if ve, ok := err.(*errors.Validation); ok { 335 return ve.ValidateName("device") 336 } else if ce, ok := err.(*errors.CompositeError); ok { 337 return ce.ValidateName("device") 338 } 339 return err 340 } 341 } 342 343 return nil 344 } 345 346 func (m *DeviceBay) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 347 348 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 349 return err 350 } 351 352 return nil 353 } 354 355 func (m *DeviceBay) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 356 357 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 358 return err 359 } 360 361 return nil 362 } 363 364 func (m *DeviceBay) contextValidateInstalledDevice(ctx context.Context, formats strfmt.Registry) error { 365 366 if m.InstalledDevice != nil { 367 if err := m.InstalledDevice.ContextValidate(ctx, formats); err != nil { 368 if ve, ok := err.(*errors.Validation); ok { 369 return ve.ValidateName("installed_device") 370 } else if ce, ok := err.(*errors.CompositeError); ok { 371 return ce.ValidateName("installed_device") 372 } 373 return err 374 } 375 } 376 377 return nil 378 } 379 380 func (m *DeviceBay) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 381 382 if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 383 return err 384 } 385 386 return nil 387 } 388 389 func (m *DeviceBay) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 390 391 for i := 0; i < len(m.Tags); i++ { 392 393 if m.Tags[i] != nil { 394 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 395 if ve, ok := err.(*errors.Validation); ok { 396 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 397 } else if ce, ok := err.(*errors.CompositeError); ok { 398 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 399 } 400 return err 401 } 402 } 403 404 } 405 406 return nil 407 } 408 409 func (m *DeviceBay) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 410 411 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 412 return err 413 } 414 415 return nil 416 } 417 418 // MarshalBinary interface implementation 419 func (m *DeviceBay) MarshalBinary() ([]byte, error) { 420 if m == nil { 421 return nil, nil 422 } 423 return swag.WriteJSON(m) 424 } 425 426 // UnmarshalBinary interface implementation 427 func (m *DeviceBay) UnmarshalBinary(b []byte) error { 428 var res DeviceBay 429 if err := swag.ReadJSON(b, &res); err != nil { 430 return err 431 } 432 *m = res 433 return nil 434 }