github.com/digitalocean/go-netbox@v0.0.2/netbox/models/rack_unit.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 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 // RackUnit rack unit 34 // 35 // swagger:model RackUnit 36 type RackUnit struct { 37 38 // device 39 Device *NestedDevice `json:"device,omitempty"` 40 41 // Display 42 // Read Only: true 43 Display string `json:"display,omitempty"` 44 45 // face 46 Face *RackUnitFace `json:"face,omitempty"` 47 48 // Id 49 // Read Only: true 50 ID int64 `json:"id,omitempty"` 51 52 // Name 53 // Read Only: true 54 // Min Length: 1 55 Name string `json:"name,omitempty"` 56 57 // Occupied 58 // Read Only: true 59 Occupied *bool `json:"occupied,omitempty"` 60 } 61 62 // Validate validates this rack unit 63 func (m *RackUnit) Validate(formats strfmt.Registry) error { 64 var res []error 65 66 if err := m.validateDevice(formats); err != nil { 67 res = append(res, err) 68 } 69 70 if err := m.validateFace(formats); err != nil { 71 res = append(res, err) 72 } 73 74 if err := m.validateName(formats); err != nil { 75 res = append(res, err) 76 } 77 78 if len(res) > 0 { 79 return errors.CompositeValidationError(res...) 80 } 81 return nil 82 } 83 84 func (m *RackUnit) validateDevice(formats strfmt.Registry) error { 85 if swag.IsZero(m.Device) { // not required 86 return nil 87 } 88 89 if m.Device != nil { 90 if err := m.Device.Validate(formats); err != nil { 91 if ve, ok := err.(*errors.Validation); ok { 92 return ve.ValidateName("device") 93 } else if ce, ok := err.(*errors.CompositeError); ok { 94 return ce.ValidateName("device") 95 } 96 return err 97 } 98 } 99 100 return nil 101 } 102 103 func (m *RackUnit) validateFace(formats strfmt.Registry) error { 104 if swag.IsZero(m.Face) { // not required 105 return nil 106 } 107 108 if m.Face != nil { 109 if err := m.Face.Validate(formats); err != nil { 110 if ve, ok := err.(*errors.Validation); ok { 111 return ve.ValidateName("face") 112 } else if ce, ok := err.(*errors.CompositeError); ok { 113 return ce.ValidateName("face") 114 } 115 return err 116 } 117 } 118 119 return nil 120 } 121 122 func (m *RackUnit) validateName(formats strfmt.Registry) error { 123 if swag.IsZero(m.Name) { // not required 124 return nil 125 } 126 127 if err := validate.MinLength("name", "body", m.Name, 1); err != nil { 128 return err 129 } 130 131 return nil 132 } 133 134 // ContextValidate validate this rack unit based on the context it is used 135 func (m *RackUnit) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 136 var res []error 137 138 if err := m.contextValidateDevice(ctx, formats); err != nil { 139 res = append(res, err) 140 } 141 142 if err := m.contextValidateDisplay(ctx, formats); err != nil { 143 res = append(res, err) 144 } 145 146 if err := m.contextValidateFace(ctx, formats); err != nil { 147 res = append(res, err) 148 } 149 150 if err := m.contextValidateID(ctx, formats); err != nil { 151 res = append(res, err) 152 } 153 154 if err := m.contextValidateName(ctx, formats); err != nil { 155 res = append(res, err) 156 } 157 158 if err := m.contextValidateOccupied(ctx, formats); err != nil { 159 res = append(res, err) 160 } 161 162 if len(res) > 0 { 163 return errors.CompositeValidationError(res...) 164 } 165 return nil 166 } 167 168 func (m *RackUnit) contextValidateDevice(ctx context.Context, formats strfmt.Registry) error { 169 170 if m.Device != nil { 171 if err := m.Device.ContextValidate(ctx, formats); err != nil { 172 if ve, ok := err.(*errors.Validation); ok { 173 return ve.ValidateName("device") 174 } else if ce, ok := err.(*errors.CompositeError); ok { 175 return ce.ValidateName("device") 176 } 177 return err 178 } 179 } 180 181 return nil 182 } 183 184 func (m *RackUnit) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 185 186 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 187 return err 188 } 189 190 return nil 191 } 192 193 func (m *RackUnit) contextValidateFace(ctx context.Context, formats strfmt.Registry) error { 194 195 if m.Face != nil { 196 if err := m.Face.ContextValidate(ctx, formats); err != nil { 197 if ve, ok := err.(*errors.Validation); ok { 198 return ve.ValidateName("face") 199 } else if ce, ok := err.(*errors.CompositeError); ok { 200 return ce.ValidateName("face") 201 } 202 return err 203 } 204 } 205 206 return nil 207 } 208 209 func (m *RackUnit) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 210 211 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 212 return err 213 } 214 215 return nil 216 } 217 218 func (m *RackUnit) contextValidateName(ctx context.Context, formats strfmt.Registry) error { 219 220 if err := validate.ReadOnly(ctx, "name", "body", string(m.Name)); err != nil { 221 return err 222 } 223 224 return nil 225 } 226 227 func (m *RackUnit) contextValidateOccupied(ctx context.Context, formats strfmt.Registry) error { 228 229 if err := validate.ReadOnly(ctx, "occupied", "body", m.Occupied); err != nil { 230 return err 231 } 232 233 return nil 234 } 235 236 // MarshalBinary interface implementation 237 func (m *RackUnit) MarshalBinary() ([]byte, error) { 238 if m == nil { 239 return nil, nil 240 } 241 return swag.WriteJSON(m) 242 } 243 244 // UnmarshalBinary interface implementation 245 func (m *RackUnit) UnmarshalBinary(b []byte) error { 246 var res RackUnit 247 if err := swag.ReadJSON(b, &res); err != nil { 248 return err 249 } 250 *m = res 251 return nil 252 } 253 254 // RackUnitFace Face 255 // 256 // swagger:model RackUnitFace 257 type RackUnitFace struct { 258 259 // label 260 // Required: true 261 // Enum: [Front Rear] 262 Label *string `json:"label"` 263 264 // value 265 // Required: true 266 // Enum: [front rear] 267 Value *string `json:"value"` 268 } 269 270 // Validate validates this rack unit face 271 func (m *RackUnitFace) Validate(formats strfmt.Registry) error { 272 var res []error 273 274 if err := m.validateLabel(formats); err != nil { 275 res = append(res, err) 276 } 277 278 if err := m.validateValue(formats); err != nil { 279 res = append(res, err) 280 } 281 282 if len(res) > 0 { 283 return errors.CompositeValidationError(res...) 284 } 285 return nil 286 } 287 288 var rackUnitFaceTypeLabelPropEnum []interface{} 289 290 func init() { 291 var res []string 292 if err := json.Unmarshal([]byte(`["Front","Rear"]`), &res); err != nil { 293 panic(err) 294 } 295 for _, v := range res { 296 rackUnitFaceTypeLabelPropEnum = append(rackUnitFaceTypeLabelPropEnum, v) 297 } 298 } 299 300 const ( 301 302 // RackUnitFaceLabelFront captures enum value "Front" 303 RackUnitFaceLabelFront string = "Front" 304 305 // RackUnitFaceLabelRear captures enum value "Rear" 306 RackUnitFaceLabelRear string = "Rear" 307 ) 308 309 // prop value enum 310 func (m *RackUnitFace) validateLabelEnum(path, location string, value string) error { 311 if err := validate.EnumCase(path, location, value, rackUnitFaceTypeLabelPropEnum, true); err != nil { 312 return err 313 } 314 return nil 315 } 316 317 func (m *RackUnitFace) validateLabel(formats strfmt.Registry) error { 318 319 if err := validate.Required("face"+"."+"label", "body", m.Label); err != nil { 320 return err 321 } 322 323 // value enum 324 if err := m.validateLabelEnum("face"+"."+"label", "body", *m.Label); err != nil { 325 return err 326 } 327 328 return nil 329 } 330 331 var rackUnitFaceTypeValuePropEnum []interface{} 332 333 func init() { 334 var res []string 335 if err := json.Unmarshal([]byte(`["front","rear"]`), &res); err != nil { 336 panic(err) 337 } 338 for _, v := range res { 339 rackUnitFaceTypeValuePropEnum = append(rackUnitFaceTypeValuePropEnum, v) 340 } 341 } 342 343 const ( 344 345 // RackUnitFaceValueFront captures enum value "front" 346 RackUnitFaceValueFront string = "front" 347 348 // RackUnitFaceValueRear captures enum value "rear" 349 RackUnitFaceValueRear string = "rear" 350 ) 351 352 // prop value enum 353 func (m *RackUnitFace) validateValueEnum(path, location string, value string) error { 354 if err := validate.EnumCase(path, location, value, rackUnitFaceTypeValuePropEnum, true); err != nil { 355 return err 356 } 357 return nil 358 } 359 360 func (m *RackUnitFace) validateValue(formats strfmt.Registry) error { 361 362 if err := validate.Required("face"+"."+"value", "body", m.Value); err != nil { 363 return err 364 } 365 366 // value enum 367 if err := m.validateValueEnum("face"+"."+"value", "body", *m.Value); err != nil { 368 return err 369 } 370 371 return nil 372 } 373 374 // ContextValidate validate this rack unit face based on the context it is used 375 func (m *RackUnitFace) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 376 var res []error 377 378 if len(res) > 0 { 379 return errors.CompositeValidationError(res...) 380 } 381 return nil 382 } 383 384 // MarshalBinary interface implementation 385 func (m *RackUnitFace) MarshalBinary() ([]byte, error) { 386 if m == nil { 387 return nil, nil 388 } 389 return swag.WriteJSON(m) 390 } 391 392 // UnmarshalBinary interface implementation 393 func (m *RackUnitFace) UnmarshalBinary(b []byte) error { 394 var res RackUnitFace 395 if err := swag.ReadJSON(b, &res); err != nil { 396 return err 397 } 398 *m = res 399 return nil 400 }