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