github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_route_target.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 // NestedRouteTarget nested route target 33 // 34 // swagger:model NestedRouteTarget 35 type NestedRouteTarget struct { 36 37 // Display 38 // Read Only: true 39 Display string `json:"display,omitempty"` 40 41 // Id 42 // Read Only: true 43 ID int64 `json:"id,omitempty"` 44 45 // Name 46 // 47 // Route target value (formatted in accordance with RFC 4360) 48 // Required: true 49 // Max Length: 21 50 // Min Length: 1 51 Name *string `json:"name"` 52 53 // Url 54 // Read Only: true 55 // Format: uri 56 URL strfmt.URI `json:"url,omitempty"` 57 } 58 59 // Validate validates this nested route target 60 func (m *NestedRouteTarget) Validate(formats strfmt.Registry) error { 61 var res []error 62 63 if err := m.validateName(formats); err != nil { 64 res = append(res, err) 65 } 66 67 if err := m.validateURL(formats); err != nil { 68 res = append(res, err) 69 } 70 71 if len(res) > 0 { 72 return errors.CompositeValidationError(res...) 73 } 74 return nil 75 } 76 77 func (m *NestedRouteTarget) validateName(formats strfmt.Registry) error { 78 79 if err := validate.Required("name", "body", m.Name); err != nil { 80 return err 81 } 82 83 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 84 return err 85 } 86 87 if err := validate.MaxLength("name", "body", *m.Name, 21); err != nil { 88 return err 89 } 90 91 return nil 92 } 93 94 func (m *NestedRouteTarget) validateURL(formats strfmt.Registry) error { 95 if swag.IsZero(m.URL) { // not required 96 return nil 97 } 98 99 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 100 return err 101 } 102 103 return nil 104 } 105 106 // ContextValidate validate this nested route target based on the context it is used 107 func (m *NestedRouteTarget) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 108 var res []error 109 110 if err := m.contextValidateDisplay(ctx, formats); err != nil { 111 res = append(res, err) 112 } 113 114 if err := m.contextValidateID(ctx, formats); err != nil { 115 res = append(res, err) 116 } 117 118 if err := m.contextValidateURL(ctx, formats); err != nil { 119 res = append(res, err) 120 } 121 122 if len(res) > 0 { 123 return errors.CompositeValidationError(res...) 124 } 125 return nil 126 } 127 128 func (m *NestedRouteTarget) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 129 130 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 131 return err 132 } 133 134 return nil 135 } 136 137 func (m *NestedRouteTarget) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 138 139 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 140 return err 141 } 142 143 return nil 144 } 145 146 func (m *NestedRouteTarget) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 147 148 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 149 return err 150 } 151 152 return nil 153 } 154 155 // MarshalBinary interface implementation 156 func (m *NestedRouteTarget) 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 *NestedRouteTarget) UnmarshalBinary(b []byte) error { 165 var res NestedRouteTarget 166 if err := swag.ReadJSON(b, &res); err != nil { 167 return err 168 } 169 *m = res 170 return nil 171 }