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