github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_device_type.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 // NestedDeviceType nested device type 33 // 34 // swagger:model NestedDeviceType 35 type NestedDeviceType struct { 36 37 // Device count 38 // Read Only: true 39 DeviceCount int64 `json:"device_count,omitempty"` 40 41 // Display 42 // Read Only: true 43 Display string `json:"display,omitempty"` 44 45 // Display name 46 // Read Only: true 47 DisplayName string `json:"display_name,omitempty"` 48 49 // Id 50 // Read Only: true 51 ID int64 `json:"id,omitempty"` 52 53 // manufacturer 54 Manufacturer *NestedManufacturer `json:"manufacturer,omitempty"` 55 56 // Model 57 // Required: true 58 // Max Length: 100 59 // Min Length: 1 60 Model *string `json:"model"` 61 62 // Slug 63 // Required: true 64 // Max Length: 100 65 // Min Length: 1 66 // Pattern: ^[-a-zA-Z0-9_]+$ 67 Slug *string `json:"slug"` 68 69 // Url 70 // Read Only: true 71 // Format: uri 72 URL strfmt.URI `json:"url,omitempty"` 73 } 74 75 // Validate validates this nested device type 76 func (m *NestedDeviceType) Validate(formats strfmt.Registry) error { 77 var res []error 78 79 if err := m.validateManufacturer(formats); err != nil { 80 res = append(res, err) 81 } 82 83 if err := m.validateModel(formats); err != nil { 84 res = append(res, err) 85 } 86 87 if err := m.validateSlug(formats); err != nil { 88 res = append(res, err) 89 } 90 91 if err := m.validateURL(formats); err != nil { 92 res = append(res, err) 93 } 94 95 if len(res) > 0 { 96 return errors.CompositeValidationError(res...) 97 } 98 return nil 99 } 100 101 func (m *NestedDeviceType) validateManufacturer(formats strfmt.Registry) error { 102 if swag.IsZero(m.Manufacturer) { // not required 103 return nil 104 } 105 106 if m.Manufacturer != nil { 107 if err := m.Manufacturer.Validate(formats); err != nil { 108 if ve, ok := err.(*errors.Validation); ok { 109 return ve.ValidateName("manufacturer") 110 } else if ce, ok := err.(*errors.CompositeError); ok { 111 return ce.ValidateName("manufacturer") 112 } 113 return err 114 } 115 } 116 117 return nil 118 } 119 120 func (m *NestedDeviceType) validateModel(formats strfmt.Registry) error { 121 122 if err := validate.Required("model", "body", m.Model); err != nil { 123 return err 124 } 125 126 if err := validate.MinLength("model", "body", *m.Model, 1); err != nil { 127 return err 128 } 129 130 if err := validate.MaxLength("model", "body", *m.Model, 100); err != nil { 131 return err 132 } 133 134 return nil 135 } 136 137 func (m *NestedDeviceType) validateSlug(formats strfmt.Registry) error { 138 139 if err := validate.Required("slug", "body", m.Slug); err != nil { 140 return err 141 } 142 143 if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil { 144 return err 145 } 146 147 if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil { 148 return err 149 } 150 151 if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil { 152 return err 153 } 154 155 return nil 156 } 157 158 func (m *NestedDeviceType) validateURL(formats strfmt.Registry) error { 159 if swag.IsZero(m.URL) { // not required 160 return nil 161 } 162 163 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 164 return err 165 } 166 167 return nil 168 } 169 170 // ContextValidate validate this nested device type based on the context it is used 171 func (m *NestedDeviceType) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 172 var res []error 173 174 if err := m.contextValidateDeviceCount(ctx, formats); err != nil { 175 res = append(res, err) 176 } 177 178 if err := m.contextValidateDisplay(ctx, formats); err != nil { 179 res = append(res, err) 180 } 181 182 if err := m.contextValidateDisplayName(ctx, formats); err != nil { 183 res = append(res, err) 184 } 185 186 if err := m.contextValidateID(ctx, formats); err != nil { 187 res = append(res, err) 188 } 189 190 if err := m.contextValidateManufacturer(ctx, formats); err != nil { 191 res = append(res, err) 192 } 193 194 if err := m.contextValidateURL(ctx, formats); err != nil { 195 res = append(res, err) 196 } 197 198 if len(res) > 0 { 199 return errors.CompositeValidationError(res...) 200 } 201 return nil 202 } 203 204 func (m *NestedDeviceType) contextValidateDeviceCount(ctx context.Context, formats strfmt.Registry) error { 205 206 if err := validate.ReadOnly(ctx, "device_count", "body", int64(m.DeviceCount)); err != nil { 207 return err 208 } 209 210 return nil 211 } 212 213 func (m *NestedDeviceType) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 214 215 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 216 return err 217 } 218 219 return nil 220 } 221 222 func (m *NestedDeviceType) contextValidateDisplayName(ctx context.Context, formats strfmt.Registry) error { 223 224 if err := validate.ReadOnly(ctx, "display_name", "body", string(m.DisplayName)); err != nil { 225 return err 226 } 227 228 return nil 229 } 230 231 func (m *NestedDeviceType) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 232 233 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 234 return err 235 } 236 237 return nil 238 } 239 240 func (m *NestedDeviceType) contextValidateManufacturer(ctx context.Context, formats strfmt.Registry) error { 241 242 if m.Manufacturer != nil { 243 if err := m.Manufacturer.ContextValidate(ctx, formats); err != nil { 244 if ve, ok := err.(*errors.Validation); ok { 245 return ve.ValidateName("manufacturer") 246 } else if ce, ok := err.(*errors.CompositeError); ok { 247 return ce.ValidateName("manufacturer") 248 } 249 return err 250 } 251 } 252 253 return nil 254 } 255 256 func (m *NestedDeviceType) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 257 258 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 259 return err 260 } 261 262 return nil 263 } 264 265 // MarshalBinary interface implementation 266 func (m *NestedDeviceType) MarshalBinary() ([]byte, error) { 267 if m == nil { 268 return nil, nil 269 } 270 return swag.WriteJSON(m) 271 } 272 273 // UnmarshalBinary interface implementation 274 func (m *NestedDeviceType) UnmarshalBinary(b []byte) error { 275 var res NestedDeviceType 276 if err := swag.ReadJSON(b, &res); err != nil { 277 return err 278 } 279 *m = res 280 return nil 281 }