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