github.com/digitalocean/go-netbox@v0.0.2/netbox/models/available_prefix.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 // AvailablePrefix available prefix 33 // 34 // swagger:model AvailablePrefix 35 type AvailablePrefix struct { 36 37 // Family 38 // Read Only: true 39 Family int64 `json:"family,omitempty"` 40 41 // Prefix 42 // Read Only: true 43 // Min Length: 1 44 Prefix string `json:"prefix,omitempty"` 45 46 // vrf 47 Vrf *NestedVRF `json:"vrf,omitempty"` 48 } 49 50 // Validate validates this available prefix 51 func (m *AvailablePrefix) Validate(formats strfmt.Registry) error { 52 var res []error 53 54 if err := m.validatePrefix(formats); err != nil { 55 res = append(res, err) 56 } 57 58 if err := m.validateVrf(formats); err != nil { 59 res = append(res, err) 60 } 61 62 if len(res) > 0 { 63 return errors.CompositeValidationError(res...) 64 } 65 return nil 66 } 67 68 func (m *AvailablePrefix) validatePrefix(formats strfmt.Registry) error { 69 if swag.IsZero(m.Prefix) { // not required 70 return nil 71 } 72 73 if err := validate.MinLength("prefix", "body", m.Prefix, 1); err != nil { 74 return err 75 } 76 77 return nil 78 } 79 80 func (m *AvailablePrefix) validateVrf(formats strfmt.Registry) error { 81 if swag.IsZero(m.Vrf) { // not required 82 return nil 83 } 84 85 if m.Vrf != nil { 86 if err := m.Vrf.Validate(formats); err != nil { 87 if ve, ok := err.(*errors.Validation); ok { 88 return ve.ValidateName("vrf") 89 } else if ce, ok := err.(*errors.CompositeError); ok { 90 return ce.ValidateName("vrf") 91 } 92 return err 93 } 94 } 95 96 return nil 97 } 98 99 // ContextValidate validate this available prefix based on the context it is used 100 func (m *AvailablePrefix) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 101 var res []error 102 103 if err := m.contextValidateFamily(ctx, formats); err != nil { 104 res = append(res, err) 105 } 106 107 if err := m.contextValidatePrefix(ctx, formats); err != nil { 108 res = append(res, err) 109 } 110 111 if err := m.contextValidateVrf(ctx, formats); err != nil { 112 res = append(res, err) 113 } 114 115 if len(res) > 0 { 116 return errors.CompositeValidationError(res...) 117 } 118 return nil 119 } 120 121 func (m *AvailablePrefix) contextValidateFamily(ctx context.Context, formats strfmt.Registry) error { 122 123 if err := validate.ReadOnly(ctx, "family", "body", int64(m.Family)); err != nil { 124 return err 125 } 126 127 return nil 128 } 129 130 func (m *AvailablePrefix) contextValidatePrefix(ctx context.Context, formats strfmt.Registry) error { 131 132 if err := validate.ReadOnly(ctx, "prefix", "body", string(m.Prefix)); err != nil { 133 return err 134 } 135 136 return nil 137 } 138 139 func (m *AvailablePrefix) contextValidateVrf(ctx context.Context, formats strfmt.Registry) error { 140 141 if m.Vrf != nil { 142 if err := m.Vrf.ContextValidate(ctx, formats); err != nil { 143 if ve, ok := err.(*errors.Validation); ok { 144 return ve.ValidateName("vrf") 145 } else if ce, ok := err.(*errors.CompositeError); ok { 146 return ce.ValidateName("vrf") 147 } 148 return err 149 } 150 } 151 152 return nil 153 } 154 155 // MarshalBinary interface implementation 156 func (m *AvailablePrefix) MarshalBinary() ([]byte, error) { 157 if m == nil { 158 return nil, nil 159 } 160 return swag.WriteJSON(m) 161 } 162 163 // UnmarshalBinary interface implementation 164 func (m *AvailablePrefix) UnmarshalBinary(b []byte) error { 165 var res AvailablePrefix 166 if err := swag.ReadJSON(b, &res); err != nil { 167 return err 168 } 169 *m = res 170 return nil 171 }