github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_interface.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 // NestedInterface nested interface 33 // 34 // swagger:model NestedInterface 35 type NestedInterface struct { 36 37 // occupied 38 // Read Only: true 39 Occupied string `json:"_occupied,omitempty"` 40 41 // Cable 42 Cable *int64 `json:"cable,omitempty"` 43 44 // device 45 Device *NestedDevice `json:"device,omitempty"` 46 47 // Display 48 // Read Only: true 49 Display string `json:"display,omitempty"` 50 51 // Id 52 // Read Only: true 53 ID int64 `json:"id,omitempty"` 54 55 // Name 56 // Required: true 57 // Max Length: 64 58 // Min Length: 1 59 Name *string `json:"name"` 60 61 // Url 62 // Read Only: true 63 // Format: uri 64 URL strfmt.URI `json:"url,omitempty"` 65 } 66 67 // Validate validates this nested interface 68 func (m *NestedInterface) Validate(formats strfmt.Registry) error { 69 var res []error 70 71 if err := m.validateDevice(formats); err != nil { 72 res = append(res, err) 73 } 74 75 if err := m.validateName(formats); err != nil { 76 res = append(res, err) 77 } 78 79 if err := m.validateURL(formats); err != nil { 80 res = append(res, err) 81 } 82 83 if len(res) > 0 { 84 return errors.CompositeValidationError(res...) 85 } 86 return nil 87 } 88 89 func (m *NestedInterface) validateDevice(formats strfmt.Registry) error { 90 if swag.IsZero(m.Device) { // not required 91 return nil 92 } 93 94 if m.Device != nil { 95 if err := m.Device.Validate(formats); err != nil { 96 if ve, ok := err.(*errors.Validation); ok { 97 return ve.ValidateName("device") 98 } else if ce, ok := err.(*errors.CompositeError); ok { 99 return ce.ValidateName("device") 100 } 101 return err 102 } 103 } 104 105 return nil 106 } 107 108 func (m *NestedInterface) validateName(formats strfmt.Registry) error { 109 110 if err := validate.Required("name", "body", m.Name); err != nil { 111 return err 112 } 113 114 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 115 return err 116 } 117 118 if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil { 119 return err 120 } 121 122 return nil 123 } 124 125 func (m *NestedInterface) validateURL(formats strfmt.Registry) error { 126 if swag.IsZero(m.URL) { // not required 127 return nil 128 } 129 130 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 131 return err 132 } 133 134 return nil 135 } 136 137 // ContextValidate validate this nested interface based on the context it is used 138 func (m *NestedInterface) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 139 var res []error 140 141 if err := m.contextValidateOccupied(ctx, formats); err != nil { 142 res = append(res, err) 143 } 144 145 if err := m.contextValidateDevice(ctx, formats); err != nil { 146 res = append(res, err) 147 } 148 149 if err := m.contextValidateDisplay(ctx, formats); err != nil { 150 res = append(res, err) 151 } 152 153 if err := m.contextValidateID(ctx, formats); err != nil { 154 res = append(res, err) 155 } 156 157 if err := m.contextValidateURL(ctx, formats); err != nil { 158 res = append(res, err) 159 } 160 161 if len(res) > 0 { 162 return errors.CompositeValidationError(res...) 163 } 164 return nil 165 } 166 167 func (m *NestedInterface) contextValidateOccupied(ctx context.Context, formats strfmt.Registry) error { 168 169 if err := validate.ReadOnly(ctx, "_occupied", "body", string(m.Occupied)); err != nil { 170 return err 171 } 172 173 return nil 174 } 175 176 func (m *NestedInterface) contextValidateDevice(ctx context.Context, formats strfmt.Registry) error { 177 178 if m.Device != nil { 179 if err := m.Device.ContextValidate(ctx, formats); err != nil { 180 if ve, ok := err.(*errors.Validation); ok { 181 return ve.ValidateName("device") 182 } else if ce, ok := err.(*errors.CompositeError); ok { 183 return ce.ValidateName("device") 184 } 185 return err 186 } 187 } 188 189 return nil 190 } 191 192 func (m *NestedInterface) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 193 194 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 195 return err 196 } 197 198 return nil 199 } 200 201 func (m *NestedInterface) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 202 203 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 204 return err 205 } 206 207 return nil 208 } 209 210 func (m *NestedInterface) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 211 212 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 213 return err 214 } 215 216 return nil 217 } 218 219 // MarshalBinary interface implementation 220 func (m *NestedInterface) MarshalBinary() ([]byte, error) { 221 if m == nil { 222 return nil, nil 223 } 224 return swag.WriteJSON(m) 225 } 226 227 // UnmarshalBinary interface implementation 228 func (m *NestedInterface) UnmarshalBinary(b []byte) error { 229 var res NestedInterface 230 if err := swag.ReadJSON(b, &res); err != nil { 231 return err 232 } 233 *m = res 234 return nil 235 }