github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_custom_field.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 "encoding/json" 26 "strconv" 27 28 "github.com/go-openapi/errors" 29 "github.com/go-openapi/strfmt" 30 "github.com/go-openapi/swag" 31 "github.com/go-openapi/validate" 32 ) 33 34 // WritableCustomField writable custom field 35 // 36 // swagger:model WritableCustomField 37 type WritableCustomField struct { 38 39 // Comma-separated list of available choices (for selection fields) 40 Choices []string `json:"choices"` 41 42 // content types 43 // Required: true 44 // Unique: true 45 ContentTypes []string `json:"content_types"` 46 47 // Default 48 // 49 // Default value for the field (must be a JSON value). Encapsulate strings with double quotes (e.g. "Foo"). 50 Default *string `json:"default,omitempty"` 51 52 // Description 53 // Max Length: 200 54 Description string `json:"description,omitempty"` 55 56 // Display 57 // Read Only: true 58 Display string `json:"display,omitempty"` 59 60 // Filter logic 61 // 62 // Loose matches any instance of a given string; exact matches the entire field. 63 // Enum: [disabled loose exact] 64 FilterLogic string `json:"filter_logic,omitempty"` 65 66 // Id 67 // Read Only: true 68 ID int64 `json:"id,omitempty"` 69 70 // Label 71 // 72 // Name of the field as displayed to users (if not provided, the field's name will be used) 73 // Max Length: 50 74 Label string `json:"label,omitempty"` 75 76 // Name 77 // 78 // Internal field name 79 // Required: true 80 // Max Length: 50 81 // Min Length: 1 82 Name *string `json:"name"` 83 84 // Required 85 // 86 // If true, this field is required when creating new objects or editing an existing object. 87 Required bool `json:"required,omitempty"` 88 89 // Type 90 // Enum: [text integer boolean date url select multiselect] 91 Type string `json:"type,omitempty"` 92 93 // Url 94 // Read Only: true 95 // Format: uri 96 URL strfmt.URI `json:"url,omitempty"` 97 98 // Maximum value 99 // 100 // Maximum allowed value (for numeric fields) 101 // Maximum: 2.147483647e+09 102 // Minimum: 0 103 ValidationMaximum *int64 `json:"validation_maximum,omitempty"` 104 105 // Minimum value 106 // 107 // Minimum allowed value (for numeric fields) 108 // Maximum: 2.147483647e+09 109 // Minimum: 0 110 ValidationMinimum *int64 `json:"validation_minimum,omitempty"` 111 112 // Validation regex 113 // 114 // Regular expression to enforce on text field values. Use ^ and $ to force matching of entire string. For example, <code>^[A-Z]{3}$</code> will limit values to exactly three uppercase letters. 115 // Max Length: 500 116 ValidationRegex string `json:"validation_regex,omitempty"` 117 118 // Weight 119 // 120 // Fields with higher weights appear lower in a form. 121 // Maximum: 32767 122 // Minimum: 0 123 Weight *int64 `json:"weight,omitempty"` 124 } 125 126 // Validate validates this writable custom field 127 func (m *WritableCustomField) Validate(formats strfmt.Registry) error { 128 var res []error 129 130 if err := m.validateChoices(formats); err != nil { 131 res = append(res, err) 132 } 133 134 if err := m.validateContentTypes(formats); err != nil { 135 res = append(res, err) 136 } 137 138 if err := m.validateDescription(formats); err != nil { 139 res = append(res, err) 140 } 141 142 if err := m.validateFilterLogic(formats); err != nil { 143 res = append(res, err) 144 } 145 146 if err := m.validateLabel(formats); err != nil { 147 res = append(res, err) 148 } 149 150 if err := m.validateName(formats); err != nil { 151 res = append(res, err) 152 } 153 154 if err := m.validateType(formats); err != nil { 155 res = append(res, err) 156 } 157 158 if err := m.validateURL(formats); err != nil { 159 res = append(res, err) 160 } 161 162 if err := m.validateValidationMaximum(formats); err != nil { 163 res = append(res, err) 164 } 165 166 if err := m.validateValidationMinimum(formats); err != nil { 167 res = append(res, err) 168 } 169 170 if err := m.validateValidationRegex(formats); err != nil { 171 res = append(res, err) 172 } 173 174 if err := m.validateWeight(formats); err != nil { 175 res = append(res, err) 176 } 177 178 if len(res) > 0 { 179 return errors.CompositeValidationError(res...) 180 } 181 return nil 182 } 183 184 func (m *WritableCustomField) validateChoices(formats strfmt.Registry) error { 185 if swag.IsZero(m.Choices) { // not required 186 return nil 187 } 188 189 for i := 0; i < len(m.Choices); i++ { 190 191 if err := validate.MinLength("choices"+"."+strconv.Itoa(i), "body", m.Choices[i], 1); err != nil { 192 return err 193 } 194 195 if err := validate.MaxLength("choices"+"."+strconv.Itoa(i), "body", m.Choices[i], 100); err != nil { 196 return err 197 } 198 199 } 200 201 return nil 202 } 203 204 func (m *WritableCustomField) validateContentTypes(formats strfmt.Registry) error { 205 206 if err := validate.Required("content_types", "body", m.ContentTypes); err != nil { 207 return err 208 } 209 210 if err := validate.UniqueItems("content_types", "body", m.ContentTypes); err != nil { 211 return err 212 } 213 214 return nil 215 } 216 217 func (m *WritableCustomField) validateDescription(formats strfmt.Registry) error { 218 if swag.IsZero(m.Description) { // not required 219 return nil 220 } 221 222 if err := validate.MaxLength("description", "body", m.Description, 200); err != nil { 223 return err 224 } 225 226 return nil 227 } 228 229 var writableCustomFieldTypeFilterLogicPropEnum []interface{} 230 231 func init() { 232 var res []string 233 if err := json.Unmarshal([]byte(`["disabled","loose","exact"]`), &res); err != nil { 234 panic(err) 235 } 236 for _, v := range res { 237 writableCustomFieldTypeFilterLogicPropEnum = append(writableCustomFieldTypeFilterLogicPropEnum, v) 238 } 239 } 240 241 const ( 242 243 // WritableCustomFieldFilterLogicDisabled captures enum value "disabled" 244 WritableCustomFieldFilterLogicDisabled string = "disabled" 245 246 // WritableCustomFieldFilterLogicLoose captures enum value "loose" 247 WritableCustomFieldFilterLogicLoose string = "loose" 248 249 // WritableCustomFieldFilterLogicExact captures enum value "exact" 250 WritableCustomFieldFilterLogicExact string = "exact" 251 ) 252 253 // prop value enum 254 func (m *WritableCustomField) validateFilterLogicEnum(path, location string, value string) error { 255 if err := validate.EnumCase(path, location, value, writableCustomFieldTypeFilterLogicPropEnum, true); err != nil { 256 return err 257 } 258 return nil 259 } 260 261 func (m *WritableCustomField) validateFilterLogic(formats strfmt.Registry) error { 262 if swag.IsZero(m.FilterLogic) { // not required 263 return nil 264 } 265 266 // value enum 267 if err := m.validateFilterLogicEnum("filter_logic", "body", m.FilterLogic); err != nil { 268 return err 269 } 270 271 return nil 272 } 273 274 func (m *WritableCustomField) validateLabel(formats strfmt.Registry) error { 275 if swag.IsZero(m.Label) { // not required 276 return nil 277 } 278 279 if err := validate.MaxLength("label", "body", m.Label, 50); err != nil { 280 return err 281 } 282 283 return nil 284 } 285 286 func (m *WritableCustomField) validateName(formats strfmt.Registry) error { 287 288 if err := validate.Required("name", "body", m.Name); err != nil { 289 return err 290 } 291 292 if err := validate.MinLength("name", "body", *m.Name, 1); err != nil { 293 return err 294 } 295 296 if err := validate.MaxLength("name", "body", *m.Name, 50); err != nil { 297 return err 298 } 299 300 return nil 301 } 302 303 var writableCustomFieldTypeTypePropEnum []interface{} 304 305 func init() { 306 var res []string 307 if err := json.Unmarshal([]byte(`["text","integer","boolean","date","url","select","multiselect"]`), &res); err != nil { 308 panic(err) 309 } 310 for _, v := range res { 311 writableCustomFieldTypeTypePropEnum = append(writableCustomFieldTypeTypePropEnum, v) 312 } 313 } 314 315 const ( 316 317 // WritableCustomFieldTypeText captures enum value "text" 318 WritableCustomFieldTypeText string = "text" 319 320 // WritableCustomFieldTypeInteger captures enum value "integer" 321 WritableCustomFieldTypeInteger string = "integer" 322 323 // WritableCustomFieldTypeBoolean captures enum value "boolean" 324 WritableCustomFieldTypeBoolean string = "boolean" 325 326 // WritableCustomFieldTypeDate captures enum value "date" 327 WritableCustomFieldTypeDate string = "date" 328 329 // WritableCustomFieldTypeURL captures enum value "url" 330 WritableCustomFieldTypeURL string = "url" 331 332 // WritableCustomFieldTypeSelect captures enum value "select" 333 WritableCustomFieldTypeSelect string = "select" 334 335 // WritableCustomFieldTypeMultiselect captures enum value "multiselect" 336 WritableCustomFieldTypeMultiselect string = "multiselect" 337 ) 338 339 // prop value enum 340 func (m *WritableCustomField) validateTypeEnum(path, location string, value string) error { 341 if err := validate.EnumCase(path, location, value, writableCustomFieldTypeTypePropEnum, true); err != nil { 342 return err 343 } 344 return nil 345 } 346 347 func (m *WritableCustomField) validateType(formats strfmt.Registry) error { 348 if swag.IsZero(m.Type) { // not required 349 return nil 350 } 351 352 // value enum 353 if err := m.validateTypeEnum("type", "body", m.Type); err != nil { 354 return err 355 } 356 357 return nil 358 } 359 360 func (m *WritableCustomField) validateURL(formats strfmt.Registry) error { 361 if swag.IsZero(m.URL) { // not required 362 return nil 363 } 364 365 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 366 return err 367 } 368 369 return nil 370 } 371 372 func (m *WritableCustomField) validateValidationMaximum(formats strfmt.Registry) error { 373 if swag.IsZero(m.ValidationMaximum) { // not required 374 return nil 375 } 376 377 if err := validate.MinimumInt("validation_maximum", "body", *m.ValidationMaximum, 0, false); err != nil { 378 return err 379 } 380 381 if err := validate.MaximumInt("validation_maximum", "body", *m.ValidationMaximum, 2.147483647e+09, false); err != nil { 382 return err 383 } 384 385 return nil 386 } 387 388 func (m *WritableCustomField) validateValidationMinimum(formats strfmt.Registry) error { 389 if swag.IsZero(m.ValidationMinimum) { // not required 390 return nil 391 } 392 393 if err := validate.MinimumInt("validation_minimum", "body", *m.ValidationMinimum, 0, false); err != nil { 394 return err 395 } 396 397 if err := validate.MaximumInt("validation_minimum", "body", *m.ValidationMinimum, 2.147483647e+09, false); err != nil { 398 return err 399 } 400 401 return nil 402 } 403 404 func (m *WritableCustomField) validateValidationRegex(formats strfmt.Registry) error { 405 if swag.IsZero(m.ValidationRegex) { // not required 406 return nil 407 } 408 409 if err := validate.MaxLength("validation_regex", "body", m.ValidationRegex, 500); err != nil { 410 return err 411 } 412 413 return nil 414 } 415 416 func (m *WritableCustomField) validateWeight(formats strfmt.Registry) error { 417 if swag.IsZero(m.Weight) { // not required 418 return nil 419 } 420 421 if err := validate.MinimumInt("weight", "body", *m.Weight, 0, false); err != nil { 422 return err 423 } 424 425 if err := validate.MaximumInt("weight", "body", *m.Weight, 32767, false); err != nil { 426 return err 427 } 428 429 return nil 430 } 431 432 // ContextValidate validate this writable custom field based on the context it is used 433 func (m *WritableCustomField) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 434 var res []error 435 436 if err := m.contextValidateDisplay(ctx, formats); err != nil { 437 res = append(res, err) 438 } 439 440 if err := m.contextValidateID(ctx, formats); err != nil { 441 res = append(res, err) 442 } 443 444 if err := m.contextValidateURL(ctx, formats); err != nil { 445 res = append(res, err) 446 } 447 448 if len(res) > 0 { 449 return errors.CompositeValidationError(res...) 450 } 451 return nil 452 } 453 454 func (m *WritableCustomField) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 455 456 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 457 return err 458 } 459 460 return nil 461 } 462 463 func (m *WritableCustomField) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 464 465 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 466 return err 467 } 468 469 return nil 470 } 471 472 func (m *WritableCustomField) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 473 474 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 475 return err 476 } 477 478 return nil 479 } 480 481 // MarshalBinary interface implementation 482 func (m *WritableCustomField) MarshalBinary() ([]byte, error) { 483 if m == nil { 484 return nil, nil 485 } 486 return swag.WriteJSON(m) 487 } 488 489 // UnmarshalBinary interface implementation 490 func (m *WritableCustomField) UnmarshalBinary(b []byte) error { 491 var res WritableCustomField 492 if err := swag.ReadJSON(b, &res); err != nil { 493 return err 494 } 495 *m = res 496 return nil 497 }