github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/models/task_card.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  	"encoding/json"
    11  	"strconv"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/strfmt"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/go-openapi/validate"
    17  )
    18  
    19  // TaskCard a card for a task
    20  //
    21  // A task card is a minimalistic representation of a task. Useful for display in list views, like a card list.
    22  //
    23  // swagger:model TaskCard
    24  type TaskCard struct {
    25  
    26  	// assigned to
    27  	AssignedTo *UserCard `json:"assignedTo,omitempty"`
    28  
    29  	// The description of the task.
    30  	//
    31  	// The task description is a longer, more detailed description of the issue.
    32  	// Perhaps it even mentions steps to reproduce.
    33  	//
    34  	Description string `json:"description,omitempty"`
    35  
    36  	// the level of effort required to get this task completed
    37  	// Maximum: 27
    38  	// Multiple Of: 3
    39  	Effort int32 `json:"effort,omitempty"`
    40  
    41  	// The id of the task.
    42  	//
    43  	// A unique identifier for the task. These are created in ascending order.
    44  	// Read Only: true
    45  	ID int64 `json:"id,omitempty"`
    46  
    47  	// the karma donated to this item.
    48  	//
    49  	// Karma is a lot like voting.  Users can donate a certain amount or karma to an issue.
    50  	// This is used to determine the weight users place on an issue. Not that +1 comments aren't great.
    51  	//
    52  	// Minimum: > 0
    53  	// Multiple Of: 0.5
    54  	Karma float64 `json:"karma,omitempty"`
    55  
    56  	// milestone
    57  	Milestone *Milestone `json:"milestone,omitempty"`
    58  
    59  	// The time at which this issue was reported.
    60  	//
    61  	// This field is read-only, so it's only sent as part of the response.
    62  	//
    63  	// Read Only: true
    64  	// Format: date-time
    65  	ReportedAt strfmt.DateTime `json:"reportedAt,omitempty"`
    66  
    67  	// severity
    68  	// Maximum: 5
    69  	// Minimum: 1
    70  	Severity int32 `json:"severity,omitempty"`
    71  
    72  	// the status of the issue
    73  	//
    74  	// There are 4 possible values for a status.
    75  	// Ignored means as much as accepted but not now, perhaps later.
    76  	//
    77  	// Required: true
    78  	// Enum: ["open","closed","ignored","rejected"]
    79  	Status *string `json:"status"`
    80  
    81  	// task tags.
    82  	//
    83  	// a task can be tagged with text blurbs.
    84  	// Max Items: 5
    85  	// Unique: true
    86  	Tags []string `json:"tags"`
    87  
    88  	// The title of the task.
    89  	//
    90  	// The title for a task, this needs to be at least 5 chars long.
    91  	// Titles don't allow any formatting, besides emoji.
    92  	//
    93  	// Required: true
    94  	// Max Length: 150
    95  	// Min Length: 5
    96  	Title *string `json:"title"`
    97  }
    98  
    99  // Validate validates this task card
   100  func (m *TaskCard) Validate(formats strfmt.Registry) error {
   101  	var res []error
   102  
   103  	if err := m.validateAssignedTo(formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if err := m.validateEffort(formats); err != nil {
   108  		res = append(res, err)
   109  	}
   110  
   111  	if err := m.validateKarma(formats); err != nil {
   112  		res = append(res, err)
   113  	}
   114  
   115  	if err := m.validateMilestone(formats); err != nil {
   116  		res = append(res, err)
   117  	}
   118  
   119  	if err := m.validateReportedAt(formats); err != nil {
   120  		res = append(res, err)
   121  	}
   122  
   123  	if err := m.validateSeverity(formats); err != nil {
   124  		res = append(res, err)
   125  	}
   126  
   127  	if err := m.validateStatus(formats); err != nil {
   128  		res = append(res, err)
   129  	}
   130  
   131  	if err := m.validateTags(formats); err != nil {
   132  		res = append(res, err)
   133  	}
   134  
   135  	if err := m.validateTitle(formats); err != nil {
   136  		res = append(res, err)
   137  	}
   138  
   139  	if len(res) > 0 {
   140  		return errors.CompositeValidationError(res...)
   141  	}
   142  	return nil
   143  }
   144  
   145  func (m *TaskCard) validateAssignedTo(formats strfmt.Registry) error {
   146  	if swag.IsZero(m.AssignedTo) { // not required
   147  		return nil
   148  	}
   149  
   150  	if m.AssignedTo != nil {
   151  		if err := m.AssignedTo.Validate(formats); err != nil {
   152  			if ve, ok := err.(*errors.Validation); ok {
   153  				return ve.ValidateName("assignedTo")
   154  			} else if ce, ok := err.(*errors.CompositeError); ok {
   155  				return ce.ValidateName("assignedTo")
   156  			}
   157  			return err
   158  		}
   159  	}
   160  
   161  	return nil
   162  }
   163  
   164  func (m *TaskCard) validateEffort(formats strfmt.Registry) error {
   165  	if swag.IsZero(m.Effort) { // not required
   166  		return nil
   167  	}
   168  
   169  	if err := validate.MaximumInt("effort", "body", int64(m.Effort), 27, false); err != nil {
   170  		return err
   171  	}
   172  
   173  	if err := validate.MultipleOfInt("effort", "body", int64(m.Effort), 3); err != nil {
   174  		return err
   175  	}
   176  
   177  	return nil
   178  }
   179  
   180  func (m *TaskCard) validateKarma(formats strfmt.Registry) error {
   181  	if swag.IsZero(m.Karma) { // not required
   182  		return nil
   183  	}
   184  
   185  	if err := validate.Minimum("karma", "body", m.Karma, 0, true); err != nil {
   186  		return err
   187  	}
   188  
   189  	if err := validate.MultipleOf("karma", "body", m.Karma, 0.5); err != nil {
   190  		return err
   191  	}
   192  
   193  	return nil
   194  }
   195  
   196  func (m *TaskCard) validateMilestone(formats strfmt.Registry) error {
   197  	if swag.IsZero(m.Milestone) { // not required
   198  		return nil
   199  	}
   200  
   201  	if m.Milestone != nil {
   202  		if err := m.Milestone.Validate(formats); err != nil {
   203  			if ve, ok := err.(*errors.Validation); ok {
   204  				return ve.ValidateName("milestone")
   205  			} else if ce, ok := err.(*errors.CompositeError); ok {
   206  				return ce.ValidateName("milestone")
   207  			}
   208  			return err
   209  		}
   210  	}
   211  
   212  	return nil
   213  }
   214  
   215  func (m *TaskCard) validateReportedAt(formats strfmt.Registry) error {
   216  	if swag.IsZero(m.ReportedAt) { // not required
   217  		return nil
   218  	}
   219  
   220  	if err := validate.FormatOf("reportedAt", "body", "date-time", m.ReportedAt.String(), formats); err != nil {
   221  		return err
   222  	}
   223  
   224  	return nil
   225  }
   226  
   227  func (m *TaskCard) validateSeverity(formats strfmt.Registry) error {
   228  	if swag.IsZero(m.Severity) { // not required
   229  		return nil
   230  	}
   231  
   232  	if err := validate.MinimumInt("severity", "body", int64(m.Severity), 1, false); err != nil {
   233  		return err
   234  	}
   235  
   236  	if err := validate.MaximumInt("severity", "body", int64(m.Severity), 5, false); err != nil {
   237  		return err
   238  	}
   239  
   240  	return nil
   241  }
   242  
   243  var taskCardTypeStatusPropEnum []interface{}
   244  
   245  func init() {
   246  	var res []string
   247  	if err := json.Unmarshal([]byte(`["open","closed","ignored","rejected"]`), &res); err != nil {
   248  		panic(err)
   249  	}
   250  	for _, v := range res {
   251  		taskCardTypeStatusPropEnum = append(taskCardTypeStatusPropEnum, v)
   252  	}
   253  }
   254  
   255  const (
   256  
   257  	// TaskCardStatusOpen captures enum value "open"
   258  	TaskCardStatusOpen string = "open"
   259  
   260  	// TaskCardStatusClosed captures enum value "closed"
   261  	TaskCardStatusClosed string = "closed"
   262  
   263  	// TaskCardStatusIgnored captures enum value "ignored"
   264  	TaskCardStatusIgnored string = "ignored"
   265  
   266  	// TaskCardStatusRejected captures enum value "rejected"
   267  	TaskCardStatusRejected string = "rejected"
   268  )
   269  
   270  // prop value enum
   271  func (m *TaskCard) validateStatusEnum(path, location string, value string) error {
   272  	if err := validate.EnumCase(path, location, value, taskCardTypeStatusPropEnum, true); err != nil {
   273  		return err
   274  	}
   275  	return nil
   276  }
   277  
   278  func (m *TaskCard) validateStatus(formats strfmt.Registry) error {
   279  
   280  	if err := validate.Required("status", "body", m.Status); err != nil {
   281  		return err
   282  	}
   283  
   284  	// value enum
   285  	if err := m.validateStatusEnum("status", "body", *m.Status); err != nil {
   286  		return err
   287  	}
   288  
   289  	return nil
   290  }
   291  
   292  func (m *TaskCard) validateTags(formats strfmt.Registry) error {
   293  	if swag.IsZero(m.Tags) { // not required
   294  		return nil
   295  	}
   296  
   297  	iTagsSize := int64(len(m.Tags))
   298  
   299  	if err := validate.MaxItems("tags", "body", iTagsSize, 5); err != nil {
   300  		return err
   301  	}
   302  
   303  	if err := validate.UniqueItems("tags", "body", m.Tags); err != nil {
   304  		return err
   305  	}
   306  
   307  	for i := 0; i < len(m.Tags); i++ {
   308  
   309  		if err := validate.MinLength("tags"+"."+strconv.Itoa(i), "body", m.Tags[i], 3); err != nil {
   310  			return err
   311  		}
   312  
   313  		if err := validate.Pattern("tags"+"."+strconv.Itoa(i), "body", m.Tags[i], `\w[\w- ]+`); err != nil {
   314  			return err
   315  		}
   316  
   317  	}
   318  
   319  	return nil
   320  }
   321  
   322  func (m *TaskCard) validateTitle(formats strfmt.Registry) error {
   323  
   324  	if err := validate.Required("title", "body", m.Title); err != nil {
   325  		return err
   326  	}
   327  
   328  	if err := validate.MinLength("title", "body", *m.Title, 5); err != nil {
   329  		return err
   330  	}
   331  
   332  	if err := validate.MaxLength("title", "body", *m.Title, 150); err != nil {
   333  		return err
   334  	}
   335  
   336  	return nil
   337  }
   338  
   339  // ContextValidate validate this task card based on the context it is used
   340  func (m *TaskCard) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   341  	var res []error
   342  
   343  	if err := m.contextValidateAssignedTo(ctx, formats); err != nil {
   344  		res = append(res, err)
   345  	}
   346  
   347  	if err := m.contextValidateID(ctx, formats); err != nil {
   348  		res = append(res, err)
   349  	}
   350  
   351  	if err := m.contextValidateMilestone(ctx, formats); err != nil {
   352  		res = append(res, err)
   353  	}
   354  
   355  	if err := m.contextValidateReportedAt(ctx, formats); err != nil {
   356  		res = append(res, err)
   357  	}
   358  
   359  	if len(res) > 0 {
   360  		return errors.CompositeValidationError(res...)
   361  	}
   362  	return nil
   363  }
   364  
   365  func (m *TaskCard) contextValidateAssignedTo(ctx context.Context, formats strfmt.Registry) error {
   366  
   367  	if m.AssignedTo != nil {
   368  
   369  		if swag.IsZero(m.AssignedTo) { // not required
   370  			return nil
   371  		}
   372  
   373  		if err := m.AssignedTo.ContextValidate(ctx, formats); err != nil {
   374  			if ve, ok := err.(*errors.Validation); ok {
   375  				return ve.ValidateName("assignedTo")
   376  			} else if ce, ok := err.(*errors.CompositeError); ok {
   377  				return ce.ValidateName("assignedTo")
   378  			}
   379  			return err
   380  		}
   381  	}
   382  
   383  	return nil
   384  }
   385  
   386  func (m *TaskCard) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   387  
   388  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   389  		return err
   390  	}
   391  
   392  	return nil
   393  }
   394  
   395  func (m *TaskCard) contextValidateMilestone(ctx context.Context, formats strfmt.Registry) error {
   396  
   397  	if m.Milestone != nil {
   398  
   399  		if swag.IsZero(m.Milestone) { // not required
   400  			return nil
   401  		}
   402  
   403  		if err := m.Milestone.ContextValidate(ctx, formats); err != nil {
   404  			if ve, ok := err.(*errors.Validation); ok {
   405  				return ve.ValidateName("milestone")
   406  			} else if ce, ok := err.(*errors.CompositeError); ok {
   407  				return ce.ValidateName("milestone")
   408  			}
   409  			return err
   410  		}
   411  	}
   412  
   413  	return nil
   414  }
   415  
   416  func (m *TaskCard) contextValidateReportedAt(ctx context.Context, formats strfmt.Registry) error {
   417  
   418  	if err := validate.ReadOnly(ctx, "reportedAt", "body", strfmt.DateTime(m.ReportedAt)); err != nil {
   419  		return err
   420  	}
   421  
   422  	return nil
   423  }
   424  
   425  // MarshalBinary interface implementation
   426  func (m *TaskCard) MarshalBinary() ([]byte, error) {
   427  	if m == nil {
   428  		return nil, nil
   429  	}
   430  	return swag.WriteJSON(m)
   431  }
   432  
   433  // UnmarshalBinary interface implementation
   434  func (m *TaskCard) UnmarshalBinary(b []byte) error {
   435  	var res TaskCard
   436  	if err := swag.ReadJSON(b, &res); err != nil {
   437  		return err
   438  	}
   439  	*m = res
   440  	return nil
   441  }