github.com/digitalocean/go-netbox@v0.0.2/netbox/models/device_role.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 26 "github.com/go-openapi/errors" 27 "github.com/go-openapi/strfmt" 28 "github.com/go-openapi/swag" 29 "github.com/go-openapi/validate" 30 ) 31 32 // DeviceRole device role 33 // 34 // swagger:model DeviceRole 35 type DeviceRole struct { 36 37 // Color 38 // Max Length: 6 39 // Min Length: 1 40 // Pattern: ^[0-9a-f]{6}$ 41 Color string `json:"color,omitempty"` 42 43 // Created 44 // Read Only: true 45 // Format: date 46 Created strfmt.Date `json:"created,omitempty"` 47 48 // Custom fields 49 CustomFields interface{} `json:"custom_fields,omitempty"` 50 51 // Description 52 // Max Length: 200 53 Description string `json:"description,omitempty"` 54 55 // Device count 56 // Read Only: true 57 DeviceCount int64 `json:"device_count,omitempty"` 58 59 // Display 60 // Read Only: true 61 Display string `json:"display,omitempty"` 62 63 // Id 64 // Read Only: true 65 ID int64 `json:"id,omitempty"` 66 67 // Last updated 68 // Read Only: true 69 // Format: date-time 70 LastUpdated strfmt.DateTime `json:"last_updated,omitempty"` 71 72 // Name 73 // Required: true 74 // Max Length: 100 75 // Min Length: 1 76 Name *string `json:"name"` 77 78 // Slug 79 // Required: true 80 // Max Length: 100 81 // Min Length: 1 82 // Pattern: ^[-a-zA-Z0-9_]+$ 83 Slug *string `json:"slug"` 84 85 // Url 86 // Read Only: true 87 // Format: uri 88 URL strfmt.URI `json:"url,omitempty"` 89 90 // Virtualmachine count 91 // Read Only: true 92 VirtualmachineCount int64 `json:"virtualmachine_count,omitempty"` 93 94 // VM Role 95 // 96 // Virtual machines may be assigned to this role 97 VMRole bool `json:"vm_role,omitempty"` 98 } 99 100 // Validate validates this device role 101 func (m *DeviceRole) Validate(formats strfmt.Registry) error { 102 var res []error 103 104 if err := m.validateColor(formats); err != nil { 105 res = append(res, err) 106 } 107 108 if err := m.validateCreated(formats); err != nil { 109 res = append(res, err) 110 } 111 112 if err := m.validateDescription(formats); err != nil { 113 res = append(res, err) 114 } 115 116 if err := m.validateLastUpdated(formats); err != nil { 117 res = append(res, err) 118 } 119 120 if err := m.validateName(formats); err != nil { 121 res = append(res, err) 122 } 123 124 if err := m.validateSlug(formats); err != nil { 125 res = append(res, err) 126 } 127 128 if err := m.validateURL(formats); err != nil { 129 res = append(res, err) 130 } 131 132 if len(res) > 0 { 133 return errors.CompositeValidationError(res...) 134 } 135 return nil 136 } 137 138 func (m *DeviceRole) validateColor(formats strfmt.Registry) error { 139 if swag.IsZero(m.Color) { // not required 140 return nil 141 } 142 143 if err := validate.MinLength("color", "body", m.Color, 1); err != nil { 144 return err 145 } 146 147 if err := validate.MaxLength("color", "body", m.Color, 6); err != nil { 148 return err 149 } 150 151 if err := validate.Pattern("color", "body", m.Color, `^[0-9a-f]{6}$`); err != nil { 152 return err 153 } 154 155 return nil 156 } 157 158 func (m *DeviceRole) validateCreated(formats strfmt.Registry) error { 159 if swag.IsZero(m.Created) { // not required 160 return nil 161 } 162 163 if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil { 164 return err 165 } 166 167 return nil 168 } 169 170 func (m *DeviceRole) validateDescription(formats strfmt.Registry) error { 171 if swag.IsZero(m.Description) { // not required 172 return nil 173 } 174 175 if err := validate.MaxLength("description", "body", m.Description, 200); err != nil { 176 return err 177 } 178 179 return nil 180 } 181 182 func (m *DeviceRole) validateLastUpdated(formats strfmt.Registry) error { 183 if swag.IsZero(m.LastUpdated) { // not required 184 return nil 185 } 186 187 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 188 return err 189 } 190 191 return nil 192 } 193 194 func (m *DeviceRole) validateName(formats strfmt.Registry) error { 195 196 if err := validate.Required("name", "body", m.Name); err != nil { 197 return err 198 } 199 200 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 201 return err 202 } 203 204 if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil { 205 return err 206 } 207 208 return nil 209 } 210 211 func (m *DeviceRole) validateSlug(formats strfmt.Registry) error { 212 213 if err := validate.Required("slug", "body", m.Slug); err != nil { 214 return err 215 } 216 217 if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil { 218 return err 219 } 220 221 if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil { 222 return err 223 } 224 225 if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil { 226 return err 227 } 228 229 return nil 230 } 231 232 func (m *DeviceRole) validateURL(formats strfmt.Registry) error { 233 if swag.IsZero(m.URL) { // not required 234 return nil 235 } 236 237 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 238 return err 239 } 240 241 return nil 242 } 243 244 // ContextValidate validate this device role based on the context it is used 245 func (m *DeviceRole) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 246 var res []error 247 248 if err := m.contextValidateCreated(ctx, formats); err != nil { 249 res = append(res, err) 250 } 251 252 if err := m.contextValidateDeviceCount(ctx, formats); err != nil { 253 res = append(res, err) 254 } 255 256 if err := m.contextValidateDisplay(ctx, formats); err != nil { 257 res = append(res, err) 258 } 259 260 if err := m.contextValidateID(ctx, formats); err != nil { 261 res = append(res, err) 262 } 263 264 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 265 res = append(res, err) 266 } 267 268 if err := m.contextValidateURL(ctx, formats); err != nil { 269 res = append(res, err) 270 } 271 272 if err := m.contextValidateVirtualmachineCount(ctx, formats); err != nil { 273 res = append(res, err) 274 } 275 276 if len(res) > 0 { 277 return errors.CompositeValidationError(res...) 278 } 279 return nil 280 } 281 282 func (m *DeviceRole) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error { 283 284 if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil { 285 return err 286 } 287 288 return nil 289 } 290 291 func (m *DeviceRole) contextValidateDeviceCount(ctx context.Context, formats strfmt.Registry) error { 292 293 if err := validate.ReadOnly(ctx, "device_count", "body", int64(m.DeviceCount)); err != nil { 294 return err 295 } 296 297 return nil 298 } 299 300 func (m *DeviceRole) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 301 302 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 303 return err 304 } 305 306 return nil 307 } 308 309 func (m *DeviceRole) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 310 311 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 312 return err 313 } 314 315 return nil 316 } 317 318 func (m *DeviceRole) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 319 320 if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 321 return err 322 } 323 324 return nil 325 } 326 327 func (m *DeviceRole) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 328 329 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 330 return err 331 } 332 333 return nil 334 } 335 336 func (m *DeviceRole) contextValidateVirtualmachineCount(ctx context.Context, formats strfmt.Registry) error { 337 338 if err := validate.ReadOnly(ctx, "virtualmachine_count", "body", int64(m.VirtualmachineCount)); err != nil { 339 return err 340 } 341 342 return nil 343 } 344 345 // MarshalBinary interface implementation 346 func (m *DeviceRole) MarshalBinary() ([]byte, error) { 347 if m == nil { 348 return nil, nil 349 } 350 return swag.WriteJSON(m) 351 } 352 353 // UnmarshalBinary interface implementation 354 func (m *DeviceRole) UnmarshalBinary(b []byte) error { 355 var res DeviceRole 356 if err := swag.ReadJSON(b, &res); err != nil { 357 return err 358 } 359 *m = res 360 return nil 361 }