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