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