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