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