github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/examples/task-tracker/models/task.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package models 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "context" 10 "strconv" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Task a structure describing a complete task. 19 // 20 // A Task is the main entity in this application. Everything revolves around tasks and managing them. 21 // 22 // swagger:model Task 23 type Task struct { 24 TaskCard 25 26 // The attached files. 27 // 28 // An issue can have at most 20 files attached to it. 29 // 30 Attachments map[string]TaskAttachmentsAnon `json:"attachments,omitempty"` 31 32 // The 5 most recent items for this issue. 33 // 34 // The detail view of an issue includes the 5 most recent comments. 35 // This field is read only, comments are added through a separate process. 36 // 37 // Read Only: true 38 Comments []*Comment `json:"comments"` 39 40 // The time at which this issue was last updated. 41 // 42 // This field is read only so it's only sent as part of the response. 43 // 44 // Read Only: true 45 // Format: date-time 46 LastUpdated strfmt.DateTime `json:"lastUpdated,omitempty"` 47 48 // last updated by 49 LastUpdatedBy *UserCard `json:"lastUpdatedBy,omitempty"` 50 51 // reported by 52 ReportedBy *UserCard `json:"reportedBy,omitempty"` 53 } 54 55 // UnmarshalJSON unmarshals this object from a JSON structure 56 func (m *Task) UnmarshalJSON(raw []byte) error { 57 // AO0 58 var aO0 TaskCard 59 if err := swag.ReadJSON(raw, &aO0); err != nil { 60 return err 61 } 62 m.TaskCard = aO0 63 64 // AO1 65 var dataAO1 struct { 66 Attachments map[string]TaskAttachmentsAnon `json:"attachments,omitempty"` 67 68 Comments []*Comment `json:"comments"` 69 70 LastUpdated strfmt.DateTime `json:"lastUpdated,omitempty"` 71 72 LastUpdatedBy *UserCard `json:"lastUpdatedBy,omitempty"` 73 74 ReportedBy *UserCard `json:"reportedBy,omitempty"` 75 } 76 if err := swag.ReadJSON(raw, &dataAO1); err != nil { 77 return err 78 } 79 80 m.Attachments = dataAO1.Attachments 81 82 m.Comments = dataAO1.Comments 83 84 m.LastUpdated = dataAO1.LastUpdated 85 86 m.LastUpdatedBy = dataAO1.LastUpdatedBy 87 88 m.ReportedBy = dataAO1.ReportedBy 89 90 return nil 91 } 92 93 // MarshalJSON marshals this object to a JSON structure 94 func (m Task) MarshalJSON() ([]byte, error) { 95 _parts := make([][]byte, 0, 2) 96 97 aO0, err := swag.WriteJSON(m.TaskCard) 98 if err != nil { 99 return nil, err 100 } 101 _parts = append(_parts, aO0) 102 var dataAO1 struct { 103 Attachments map[string]TaskAttachmentsAnon `json:"attachments,omitempty"` 104 105 Comments []*Comment `json:"comments"` 106 107 LastUpdated strfmt.DateTime `json:"lastUpdated,omitempty"` 108 109 LastUpdatedBy *UserCard `json:"lastUpdatedBy,omitempty"` 110 111 ReportedBy *UserCard `json:"reportedBy,omitempty"` 112 } 113 114 dataAO1.Attachments = m.Attachments 115 116 dataAO1.Comments = m.Comments 117 118 dataAO1.LastUpdated = m.LastUpdated 119 120 dataAO1.LastUpdatedBy = m.LastUpdatedBy 121 122 dataAO1.ReportedBy = m.ReportedBy 123 124 jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) 125 if errAO1 != nil { 126 return nil, errAO1 127 } 128 _parts = append(_parts, jsonDataAO1) 129 return swag.ConcatJSON(_parts...), nil 130 } 131 132 // Validate validates this task 133 func (m *Task) Validate(formats strfmt.Registry) error { 134 var res []error 135 136 // validation for a type composition with TaskCard 137 if err := m.TaskCard.Validate(formats); err != nil { 138 res = append(res, err) 139 } 140 141 if err := m.validateAttachments(formats); err != nil { 142 res = append(res, err) 143 } 144 145 if err := m.validateComments(formats); err != nil { 146 res = append(res, err) 147 } 148 149 if err := m.validateLastUpdated(formats); err != nil { 150 res = append(res, err) 151 } 152 153 if err := m.validateLastUpdatedBy(formats); err != nil { 154 res = append(res, err) 155 } 156 157 if err := m.validateReportedBy(formats); err != nil { 158 res = append(res, err) 159 } 160 161 if len(res) > 0 { 162 return errors.CompositeValidationError(res...) 163 } 164 return nil 165 } 166 167 func (m *Task) validateAttachments(formats strfmt.Registry) error { 168 169 if swag.IsZero(m.Attachments) { // not required 170 return nil 171 } 172 173 for k := range m.Attachments { 174 175 if swag.IsZero(m.Attachments[k]) { // not required 176 continue 177 } 178 if val, ok := m.Attachments[k]; ok { 179 if err := val.Validate(formats); err != nil { 180 if ve, ok := err.(*errors.Validation); ok { 181 return ve.ValidateName("attachments" + "." + k) 182 } else if ce, ok := err.(*errors.CompositeError); ok { 183 return ce.ValidateName("attachments" + "." + k) 184 } 185 return err 186 } 187 } 188 189 } 190 191 return nil 192 } 193 194 func (m *Task) validateComments(formats strfmt.Registry) error { 195 196 if swag.IsZero(m.Comments) { // not required 197 return nil 198 } 199 200 for i := 0; i < len(m.Comments); i++ { 201 if swag.IsZero(m.Comments[i]) { // not required 202 continue 203 } 204 205 if m.Comments[i] != nil { 206 if err := m.Comments[i].Validate(formats); err != nil { 207 if ve, ok := err.(*errors.Validation); ok { 208 return ve.ValidateName("comments" + "." + strconv.Itoa(i)) 209 } else if ce, ok := err.(*errors.CompositeError); ok { 210 return ce.ValidateName("comments" + "." + strconv.Itoa(i)) 211 } 212 return err 213 } 214 } 215 216 } 217 218 return nil 219 } 220 221 func (m *Task) validateLastUpdated(formats strfmt.Registry) error { 222 223 if swag.IsZero(m.LastUpdated) { // not required 224 return nil 225 } 226 227 if err := validate.FormatOf("lastUpdated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 228 return err 229 } 230 231 return nil 232 } 233 234 func (m *Task) validateLastUpdatedBy(formats strfmt.Registry) error { 235 236 if swag.IsZero(m.LastUpdatedBy) { // not required 237 return nil 238 } 239 240 if m.LastUpdatedBy != nil { 241 if err := m.LastUpdatedBy.Validate(formats); err != nil { 242 if ve, ok := err.(*errors.Validation); ok { 243 return ve.ValidateName("lastUpdatedBy") 244 } else if ce, ok := err.(*errors.CompositeError); ok { 245 return ce.ValidateName("lastUpdatedBy") 246 } 247 return err 248 } 249 } 250 251 return nil 252 } 253 254 func (m *Task) validateReportedBy(formats strfmt.Registry) error { 255 256 if swag.IsZero(m.ReportedBy) { // not required 257 return nil 258 } 259 260 if m.ReportedBy != nil { 261 if err := m.ReportedBy.Validate(formats); err != nil { 262 if ve, ok := err.(*errors.Validation); ok { 263 return ve.ValidateName("reportedBy") 264 } else if ce, ok := err.(*errors.CompositeError); ok { 265 return ce.ValidateName("reportedBy") 266 } 267 return err 268 } 269 } 270 271 return nil 272 } 273 274 // ContextValidate validate this task based on the context it is used 275 func (m *Task) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 276 var res []error 277 278 // validation for a type composition with TaskCard 279 if err := m.TaskCard.ContextValidate(ctx, formats); err != nil { 280 res = append(res, err) 281 } 282 283 if err := m.contextValidateAttachments(ctx, formats); err != nil { 284 res = append(res, err) 285 } 286 287 if err := m.contextValidateComments(ctx, formats); err != nil { 288 res = append(res, err) 289 } 290 291 if err := m.contextValidateLastUpdated(ctx, formats); err != nil { 292 res = append(res, err) 293 } 294 295 if err := m.contextValidateLastUpdatedBy(ctx, formats); err != nil { 296 res = append(res, err) 297 } 298 299 if err := m.contextValidateReportedBy(ctx, formats); err != nil { 300 res = append(res, err) 301 } 302 303 if len(res) > 0 { 304 return errors.CompositeValidationError(res...) 305 } 306 return nil 307 } 308 309 func (m *Task) contextValidateAttachments(ctx context.Context, formats strfmt.Registry) error { 310 311 for k := range m.Attachments { 312 313 if val, ok := m.Attachments[k]; ok { 314 if err := val.ContextValidate(ctx, formats); err != nil { 315 return err 316 } 317 } 318 319 } 320 321 return nil 322 } 323 324 func (m *Task) contextValidateComments(ctx context.Context, formats strfmt.Registry) error { 325 326 if err := validate.ReadOnly(ctx, "comments", "body", []*Comment(m.Comments)); err != nil { 327 return err 328 } 329 330 for i := 0; i < len(m.Comments); i++ { 331 332 if m.Comments[i] != nil { 333 if err := m.Comments[i].ContextValidate(ctx, formats); err != nil { 334 if ve, ok := err.(*errors.Validation); ok { 335 return ve.ValidateName("comments" + "." + strconv.Itoa(i)) 336 } else if ce, ok := err.(*errors.CompositeError); ok { 337 return ce.ValidateName("comments" + "." + strconv.Itoa(i)) 338 } 339 return err 340 } 341 } 342 343 } 344 345 return nil 346 } 347 348 func (m *Task) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error { 349 350 if err := validate.ReadOnly(ctx, "lastUpdated", "body", strfmt.DateTime(m.LastUpdated)); err != nil { 351 return err 352 } 353 354 return nil 355 } 356 357 func (m *Task) contextValidateLastUpdatedBy(ctx context.Context, formats strfmt.Registry) error { 358 359 if m.LastUpdatedBy != nil { 360 if err := m.LastUpdatedBy.ContextValidate(ctx, formats); err != nil { 361 if ve, ok := err.(*errors.Validation); ok { 362 return ve.ValidateName("lastUpdatedBy") 363 } else if ce, ok := err.(*errors.CompositeError); ok { 364 return ce.ValidateName("lastUpdatedBy") 365 } 366 return err 367 } 368 } 369 370 return nil 371 } 372 373 func (m *Task) contextValidateReportedBy(ctx context.Context, formats strfmt.Registry) error { 374 375 if m.ReportedBy != nil { 376 if err := m.ReportedBy.ContextValidate(ctx, formats); err != nil { 377 if ve, ok := err.(*errors.Validation); ok { 378 return ve.ValidateName("reportedBy") 379 } else if ce, ok := err.(*errors.CompositeError); ok { 380 return ce.ValidateName("reportedBy") 381 } 382 return err 383 } 384 } 385 386 return nil 387 } 388 389 // MarshalBinary interface implementation 390 func (m *Task) MarshalBinary() ([]byte, error) { 391 if m == nil { 392 return nil, nil 393 } 394 return swag.WriteJSON(m) 395 } 396 397 // UnmarshalBinary interface implementation 398 func (m *Task) UnmarshalBinary(b []byte) error { 399 var res Task 400 if err := swag.ReadJSON(b, &res); err != nil { 401 return err 402 } 403 *m = res 404 return nil 405 } 406 407 // TaskAttachmentsAnon task attachments anon 408 // 409 // swagger:model TaskAttachmentsAnon 410 type TaskAttachmentsAnon struct { 411 412 // The content type of the file. 413 // 414 // The content type of the file is inferred from the upload request. 415 // 416 // Read Only: true 417 ContentType string `json:"contentType,omitempty"` 418 419 // Extra information to attach to the file. 420 // 421 // This is a free form text field with support for github flavored markdown. 422 // 423 // Min Length: 3 424 Description string `json:"description,omitempty"` 425 426 // The name of the file. 427 // 428 // This name is inferred from the upload request. 429 // 430 // Read Only: true 431 Name string `json:"name,omitempty"` 432 433 // The file size in bytes. 434 // 435 // This property was generated during the upload request of the file. 436 // Read Only: true 437 Size float64 `json:"size,omitempty"` 438 439 // The url to download or view the file. 440 // 441 // This URL is generated on the server, based on where it was able to store the file when it was uploaded. 442 // 443 // Read Only: true 444 // Format: uri 445 URL strfmt.URI `json:"url,omitempty"` 446 } 447 448 // Validate validates this task attachments anon 449 func (m *TaskAttachmentsAnon) Validate(formats strfmt.Registry) error { 450 var res []error 451 452 if err := m.validateDescription(formats); err != nil { 453 res = append(res, err) 454 } 455 456 if err := m.validateURL(formats); err != nil { 457 res = append(res, err) 458 } 459 460 if len(res) > 0 { 461 return errors.CompositeValidationError(res...) 462 } 463 return nil 464 } 465 466 func (m *TaskAttachmentsAnon) validateDescription(formats strfmt.Registry) error { 467 if swag.IsZero(m.Description) { // not required 468 return nil 469 } 470 471 if err := validate.MinLength("description", "body", m.Description, 3); err != nil { 472 return err 473 } 474 475 return nil 476 } 477 478 func (m *TaskAttachmentsAnon) validateURL(formats strfmt.Registry) error { 479 if swag.IsZero(m.URL) { // not required 480 return nil 481 } 482 483 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 484 return err 485 } 486 487 return nil 488 } 489 490 // ContextValidate validate this task attachments anon based on the context it is used 491 func (m *TaskAttachmentsAnon) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 492 var res []error 493 494 if err := m.contextValidateContentType(ctx, formats); err != nil { 495 res = append(res, err) 496 } 497 498 if err := m.contextValidateName(ctx, formats); err != nil { 499 res = append(res, err) 500 } 501 502 if err := m.contextValidateSize(ctx, formats); err != nil { 503 res = append(res, err) 504 } 505 506 if err := m.contextValidateURL(ctx, formats); err != nil { 507 res = append(res, err) 508 } 509 510 if len(res) > 0 { 511 return errors.CompositeValidationError(res...) 512 } 513 return nil 514 } 515 516 func (m *TaskAttachmentsAnon) contextValidateContentType(ctx context.Context, formats strfmt.Registry) error { 517 518 if err := validate.ReadOnly(ctx, "contentType", "body", string(m.ContentType)); err != nil { 519 return err 520 } 521 522 return nil 523 } 524 525 func (m *TaskAttachmentsAnon) contextValidateName(ctx context.Context, formats strfmt.Registry) error { 526 527 if err := validate.ReadOnly(ctx, "name", "body", string(m.Name)); err != nil { 528 return err 529 } 530 531 return nil 532 } 533 534 func (m *TaskAttachmentsAnon) contextValidateSize(ctx context.Context, formats strfmt.Registry) error { 535 536 if err := validate.ReadOnly(ctx, "size", "body", float64(m.Size)); err != nil { 537 return err 538 } 539 540 return nil 541 } 542 543 func (m *TaskAttachmentsAnon) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 544 545 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 546 return err 547 } 548 549 return nil 550 } 551 552 // MarshalBinary interface implementation 553 func (m *TaskAttachmentsAnon) MarshalBinary() ([]byte, error) { 554 if m == nil { 555 return nil, nil 556 } 557 return swag.WriteJSON(m) 558 } 559 560 // UnmarshalBinary interface implementation 561 func (m *TaskAttachmentsAnon) UnmarshalBinary(b []byte) error { 562 var res TaskAttachmentsAnon 563 if err := swag.ReadJSON(b, &res); err != nil { 564 return err 565 } 566 *m = res 567 return nil 568 }