github.com/digitalocean/go-netbox@v0.0.2/netbox/models/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 // Role role 33 // 34 // swagger:model Role 35 type Role struct { 36 37 // Created 38 // Read Only: true 39 // Format: date 40 Created strfmt.Date `json:"created,omitempty"` 41 42 // Custom fields 43 CustomFields interface{} `json:"custom_fields,omitempty"` 44 45 // Description 46 // Max Length: 200 47 Description string `json:"description,omitempty"` 48 49 // Display 50 // Read Only: true 51 Display string `json:"display,omitempty"` 52 53 // Id 54 // Read Only: true 55 ID int64 `json:"id,omitempty"` 56 57 // Last updated 58 // Read Only: true 59 // Format: date-time 60 LastUpdated strfmt.DateTime `json:"last_updated,omitempty"` 61 62 // Name 63 // Required: true 64 // Max Length: 100 65 // Min Length: 1 66 Name *string `json:"name"` 67 68 // Prefix count 69 // Read Only: true 70 PrefixCount int64 `json:"prefix_count,omitempty"` 71 72 // Slug 73 // Required: true 74 // Max Length: 100 75 // Min Length: 1 76 // Pattern: ^[-a-zA-Z0-9_]+$ 77 Slug *string `json:"slug"` 78 79 // Url 80 // Read Only: true 81 // Format: uri 82 URL strfmt.URI `json:"url,omitempty"` 83 84 // Vlan count 85 // Read Only: true 86 VlanCount int64 `json:"vlan_count,omitempty"` 87 88 // Weight 89 // Maximum: 32767 90 // Minimum: 0 91 Weight *int64 `json:"weight,omitempty"` 92 } 93 94 // Validate validates this role 95 func (m *Role) Validate(formats strfmt.Registry) error { 96 var res []error 97 98 if err := m.validateCreated(formats); err != nil { 99 res = append(res, err) 100 } 101 102 if err := m.validateDescription(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.validateSlug(formats); err != nil { 115 res = append(res, err) 116 } 117 118 if err := m.validateURL(formats); err != nil { 119 res = append(res, err) 120 } 121 122 if err := m.validateWeight(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 *Role) 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 *Role) validateDescription(formats strfmt.Registry) error { 145 if swag.IsZero(m.Description) { // not required 146 return nil 147 } 148 149 if err := validate.MaxLength("description", "body", m.Description, 200); err != nil { 150 return err 151 } 152 153 return nil 154 } 155 156 func (m *Role) validateLastUpdated(formats strfmt.Registry) error { 157 if swag.IsZero(m.LastUpdated) { // not required 158 return nil 159 } 160 161 if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 162 return err 163 } 164 165 return nil 166 } 167 168 func (m *Role) validateName(formats strfmt.Registry) error { 169 170 if err := validate.Required("name", "body", m.Name); err != nil { 171 return err 172 } 173 174 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 175 return err 176 } 177 178 if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil { 179 return err 180 } 181 182 return nil 183 } 184 185 func (m *Role) validateSlug(formats strfmt.Registry) error { 186 187 if err := validate.Required("slug", "body", m.Slug); err != nil { 188 return err 189 } 190 191 if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil { 192 return err 193 } 194 195 if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil { 196 return err 197 } 198 199 if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil { 200 return err 201 } 202 203 return nil 204 } 205 206 func (m *Role) validateURL(formats strfmt.Registry) error { 207 if swag.IsZero(m.URL) { // not required 208 return nil 209 } 210 211 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 212 return err 213 } 214 215 return nil 216 } 217 218 func (m *Role) validateWeight(formats strfmt.Registry) error { 219 if swag.IsZero(m.Weight) { // not required 220 return nil 221 } 222 223 if err := validate.MinimumInt("weight", "body", *m.Weight, 0, false); err != nil { 224 return err 225 } 226 227 if err := validate.MaximumInt("weight", "body", *m.Weight, 32767, false); err != nil { 228 return err 229 } 230 231 return nil 232 } 233 234 // ContextValidate validate this role based on the context it is used 235 func (m *Role) 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.contextValidatePrefixCount(ctx, formats); err != nil { 255 res = append(res, err) 256 } 257 258 if err := m.contextValidateURL(ctx, formats); err != nil { 259 res = append(res, err) 260 } 261 262 if err := m.contextValidateVlanCount(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 *Role) 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 *Role) 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 *Role) 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 *Role) 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 *Role) contextValidatePrefixCount(ctx context.Context, formats strfmt.Registry) error { 309 310 if err := validate.ReadOnly(ctx, "prefix_count", "body", int64(m.PrefixCount)); err != nil { 311 return err 312 } 313 314 return nil 315 } 316 317 func (m *Role) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 318 319 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 320 return err 321 } 322 323 return nil 324 } 325 326 func (m *Role) contextValidateVlanCount(ctx context.Context, formats strfmt.Registry) error { 327 328 if err := validate.ReadOnly(ctx, "vlan_count", "body", int64(m.VlanCount)); err != nil { 329 return err 330 } 331 332 return nil 333 } 334 335 // MarshalBinary interface implementation 336 func (m *Role) MarshalBinary() ([]byte, error) { 337 if m == nil { 338 return nil, nil 339 } 340 return swag.WriteJSON(m) 341 } 342 343 // UnmarshalBinary interface implementation 344 func (m *Role) UnmarshalBinary(b []byte) error { 345 var res Role 346 if err := swag.ReadJSON(b, &res); err != nil { 347 return err 348 } 349 *m = res 350 return nil 351 }