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