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