Validate reports whether the create-task request is internally consistent.
(path string)
| 787 | |
| 788 | // Validate reports whether the create-task request is internally consistent. |
| 789 | func (r CreateTask) Validate(path string) error { |
| 790 | if err := ValidateScopeBinding(r.Scope, r.WorkspaceID, path, "workspace_id"); err != nil { |
| 791 | return err |
| 792 | } |
| 793 | if strings.TrimSpace(r.Title) == "" { |
| 794 | return fmt.Errorf("%w: %s is required", ErrValidation, nestedPath(path, "title")) |
| 795 | } |
| 796 | if strings.TrimSpace(r.ParentTaskID) != "" && strings.TrimSpace(r.ID) != "" && |
| 797 | strings.TrimSpace(r.ParentTaskID) == strings.TrimSpace(r.ID) { |
| 798 | return fmt.Errorf( |
| 799 | "%w: %s cannot equal %s", |
| 800 | ErrValidation, |
| 801 | nestedPath(path, "parent_task_id"), |
| 802 | nestedPath(path, "id"), |
| 803 | ) |
| 804 | } |
| 805 | if r.Owner != nil { |
| 806 | if err := r.Owner.Validate(nestedPath(path, "owner")); err != nil { |
| 807 | return err |
| 808 | } |
| 809 | } |
| 810 | if r.Priority.Normalize() != "" { |
| 811 | if err := r.Priority.Validate(nestedPath(path, "priority")); err != nil { |
| 812 | return err |
| 813 | } |
| 814 | } |
| 815 | if r.MaxAttempts != nil { |
| 816 | if err := validateTaskMaxAttempts(*r.MaxAttempts, nestedPath(path, "max_attempts"), false); err != nil { |
| 817 | return err |
| 818 | } |
| 819 | } |
| 820 | if r.ApprovalPolicy.Normalize() != "" { |
| 821 | if err := r.ApprovalPolicy.Validate(nestedPath(path, "approval_policy")); err != nil { |
| 822 | return err |
| 823 | } |
| 824 | } |
| 825 | if err := ValidateMetadataSize(r.Metadata, nestedPath(path, "metadata")); err != nil { |
| 826 | return err |
| 827 | } |
| 828 | return nil |
| 829 | } |
| 830 | |
| 831 | // Validate reports whether the task patch contains at least one mutable field and valid values. |
| 832 | func (p Patch) Validate(path string) error { |
no test coverage detected