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