github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_power_panel.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 // WritablePowerPanel writable power panel 34 // 35 // swagger:model WritablePowerPanel 36 type WritablePowerPanel struct { 37 38 // Custom fields 39 CustomFields interface{} `json:"custom_fields,omitempty"` 40 41 // Display 42 // Read Only: true 43 Display string `json:"display,omitempty"` 44 45 // Id 46 // Read Only: true 47 ID int64 `json:"id,omitempty"` 48 49 // Location 50 Location *int64 `json:"location,omitempty"` 51 52 // Name 53 // Required: true 54 // Max Length: 100 55 // Min Length: 1 56 Name *string `json:"name"` 57 58 // Powerfeed count 59 // Read Only: true 60 PowerfeedCount int64 `json:"powerfeed_count,omitempty"` 61 62 // Site 63 // Required: true 64 Site *int64 `json:"site"` 65 66 // tags 67 Tags []*NestedTag `json:"tags"` 68 69 // Url 70 // Read Only: true 71 // Format: uri 72 URL strfmt.URI `json:"url,omitempty"` 73 } 74 75 // Validate validates this writable power panel 76 func (m *WritablePowerPanel) Validate(formats strfmt.Registry) error { 77 var res []error 78 79 if err := m.validateName(formats); err != nil { 80 res = append(res, err) 81 } 82 83 if err := m.validateSite(formats); err != nil { 84 res = append(res, err) 85 } 86 87 if err := m.validateTags(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 *WritablePowerPanel) validateName(formats strfmt.Registry) error { 102 103 if err := validate.Required("name", "body", m.Name); err != nil { 104 return err 105 } 106 107 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 108 return err 109 } 110 111 if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil { 112 return err 113 } 114 115 return nil 116 } 117 118 func (m *WritablePowerPanel) validateSite(formats strfmt.Registry) error { 119 120 if err := validate.Required("site", "body", m.Site); err != nil { 121 return err 122 } 123 124 return nil 125 } 126 127 func (m *WritablePowerPanel) validateTags(formats strfmt.Registry) error { 128 if swag.IsZero(m.Tags) { // not required 129 return nil 130 } 131 132 for i := 0; i < len(m.Tags); i++ { 133 if swag.IsZero(m.Tags[i]) { // not required 134 continue 135 } 136 137 if m.Tags[i] != nil { 138 if err := m.Tags[i].Validate(formats); err != nil { 139 if ve, ok := err.(*errors.Validation); ok { 140 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 141 } else if ce, ok := err.(*errors.CompositeError); ok { 142 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 143 } 144 return err 145 } 146 } 147 148 } 149 150 return nil 151 } 152 153 func (m *WritablePowerPanel) validateURL(formats strfmt.Registry) error { 154 if swag.IsZero(m.URL) { // not required 155 return nil 156 } 157 158 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 159 return err 160 } 161 162 return nil 163 } 164 165 // ContextValidate validate this writable power panel based on the context it is used 166 func (m *WritablePowerPanel) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 167 var res []error 168 169 if err := m.contextValidateDisplay(ctx, formats); err != nil { 170 res = append(res, err) 171 } 172 173 if err := m.contextValidateID(ctx, formats); err != nil { 174 res = append(res, err) 175 } 176 177 if err := m.contextValidatePowerfeedCount(ctx, formats); err != nil { 178 res = append(res, err) 179 } 180 181 if err := m.contextValidateTags(ctx, formats); err != nil { 182 res = append(res, err) 183 } 184 185 if err := m.contextValidateURL(ctx, formats); err != nil { 186 res = append(res, err) 187 } 188 189 if len(res) > 0 { 190 return errors.CompositeValidationError(res...) 191 } 192 return nil 193 } 194 195 func (m *WritablePowerPanel) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 196 197 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 198 return err 199 } 200 201 return nil 202 } 203 204 func (m *WritablePowerPanel) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 205 206 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 207 return err 208 } 209 210 return nil 211 } 212 213 func (m *WritablePowerPanel) contextValidatePowerfeedCount(ctx context.Context, formats strfmt.Registry) error { 214 215 if err := validate.ReadOnly(ctx, "powerfeed_count", "body", int64(m.PowerfeedCount)); err != nil { 216 return err 217 } 218 219 return nil 220 } 221 222 func (m *WritablePowerPanel) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 223 224 for i := 0; i < len(m.Tags); i++ { 225 226 if m.Tags[i] != nil { 227 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 228 if ve, ok := err.(*errors.Validation); ok { 229 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 230 } else if ce, ok := err.(*errors.CompositeError); ok { 231 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 232 } 233 return err 234 } 235 } 236 237 } 238 239 return nil 240 } 241 242 func (m *WritablePowerPanel) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 243 244 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 245 return err 246 } 247 248 return nil 249 } 250 251 // MarshalBinary interface implementation 252 func (m *WritablePowerPanel) MarshalBinary() ([]byte, error) { 253 if m == nil { 254 return nil, nil 255 } 256 return swag.WriteJSON(m) 257 } 258 259 // UnmarshalBinary interface implementation 260 func (m *WritablePowerPanel) UnmarshalBinary(b []byte) error { 261 var res WritablePowerPanel 262 if err := swag.ReadJSON(b, &res); err != nil { 263 return err 264 } 265 *m = res 266 return nil 267 }