github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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  
   334  			if swag.IsZero(m.Comments[i]) { // not required
   335  				return nil
   336  			}
   337  
   338  			if err := m.Comments[i].ContextValidate(ctx, formats); err != nil {
   339  				if ve, ok := err.(*errors.Validation); ok {
   340  					return ve.ValidateName("comments" + "." + strconv.Itoa(i))
   341  				} else if ce, ok := err.(*errors.CompositeError); ok {
   342  					return ce.ValidateName("comments" + "." + strconv.Itoa(i))
   343  				}
   344  				return err
   345  			}
   346  		}
   347  
   348  	}
   349  
   350  	return nil
   351  }
   352  
   353  func (m *Task) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   354  
   355  	if err := validate.ReadOnly(ctx, "lastUpdated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   356  		return err
   357  	}
   358  
   359  	return nil
   360  }
   361  
   362  func (m *Task) contextValidateLastUpdatedBy(ctx context.Context, formats strfmt.Registry) error {
   363  
   364  	if m.LastUpdatedBy != nil {
   365  
   366  		if swag.IsZero(m.LastUpdatedBy) { // not required
   367  			return nil
   368  		}
   369  
   370  		if err := m.LastUpdatedBy.ContextValidate(ctx, formats); err != nil {
   371  			if ve, ok := err.(*errors.Validation); ok {
   372  				return ve.ValidateName("lastUpdatedBy")
   373  			} else if ce, ok := err.(*errors.CompositeError); ok {
   374  				return ce.ValidateName("lastUpdatedBy")
   375  			}
   376  			return err
   377  		}
   378  	}
   379  
   380  	return nil
   381  }
   382  
   383  func (m *Task) contextValidateReportedBy(ctx context.Context, formats strfmt.Registry) error {
   384  
   385  	if m.ReportedBy != nil {
   386  
   387  		if swag.IsZero(m.ReportedBy) { // not required
   388  			return nil
   389  		}
   390  
   391  		if err := m.ReportedBy.ContextValidate(ctx, formats); err != nil {
   392  			if ve, ok := err.(*errors.Validation); ok {
   393  				return ve.ValidateName("reportedBy")
   394  			} else if ce, ok := err.(*errors.CompositeError); ok {
   395  				return ce.ValidateName("reportedBy")
   396  			}
   397  			return err
   398  		}
   399  	}
   400  
   401  	return nil
   402  }
   403  
   404  // MarshalBinary interface implementation
   405  func (m *Task) MarshalBinary() ([]byte, error) {
   406  	if m == nil {
   407  		return nil, nil
   408  	}
   409  	return swag.WriteJSON(m)
   410  }
   411  
   412  // UnmarshalBinary interface implementation
   413  func (m *Task) UnmarshalBinary(b []byte) error {
   414  	var res Task
   415  	if err := swag.ReadJSON(b, &res); err != nil {
   416  		return err
   417  	}
   418  	*m = res
   419  	return nil
   420  }
   421  
   422  // TaskAttachmentsAnon task attachments anon
   423  //
   424  // swagger:model TaskAttachmentsAnon
   425  type TaskAttachmentsAnon struct {
   426  
   427  	// The content type of the file.
   428  	//
   429  	// The content type of the file is inferred from the upload request.
   430  	//
   431  	// Read Only: true
   432  	ContentType string `json:"contentType,omitempty"`
   433  
   434  	// Extra information to attach to the file.
   435  	//
   436  	// This is a free form text field with support for github flavored markdown.
   437  	//
   438  	// Min Length: 3
   439  	Description string `json:"description,omitempty"`
   440  
   441  	// The name of the file.
   442  	//
   443  	// This name is inferred from the upload request.
   444  	//
   445  	// Read Only: true
   446  	Name string `json:"name,omitempty"`
   447  
   448  	// The file size in bytes.
   449  	//
   450  	// This property was generated during the upload request of the file.
   451  	// Read Only: true
   452  	Size float64 `json:"size,omitempty"`
   453  
   454  	// The url to download or view the file.
   455  	//
   456  	// This URL is generated on the server, based on where it was able to store the file when it was uploaded.
   457  	//
   458  	// Read Only: true
   459  	// Format: uri
   460  	URL strfmt.URI `json:"url,omitempty"`
   461  }
   462  
   463  // Validate validates this task attachments anon
   464  func (m *TaskAttachmentsAnon) Validate(formats strfmt.Registry) error {
   465  	var res []error
   466  
   467  	if err := m.validateDescription(formats); err != nil {
   468  		res = append(res, err)
   469  	}
   470  
   471  	if err := m.validateURL(formats); err != nil {
   472  		res = append(res, err)
   473  	}
   474  
   475  	if len(res) > 0 {
   476  		return errors.CompositeValidationError(res...)
   477  	}
   478  	return nil
   479  }
   480  
   481  func (m *TaskAttachmentsAnon) validateDescription(formats strfmt.Registry) error {
   482  	if swag.IsZero(m.Description) { // not required
   483  		return nil
   484  	}
   485  
   486  	if err := validate.MinLength("description", "body", m.Description, 3); err != nil {
   487  		return err
   488  	}
   489  
   490  	return nil
   491  }
   492  
   493  func (m *TaskAttachmentsAnon) validateURL(formats strfmt.Registry) error {
   494  	if swag.IsZero(m.URL) { // not required
   495  		return nil
   496  	}
   497  
   498  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   499  		return err
   500  	}
   501  
   502  	return nil
   503  }
   504  
   505  // ContextValidate validate this task attachments anon based on the context it is used
   506  func (m *TaskAttachmentsAnon) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   507  	var res []error
   508  
   509  	if err := m.contextValidateContentType(ctx, formats); err != nil {
   510  		res = append(res, err)
   511  	}
   512  
   513  	if err := m.contextValidateName(ctx, formats); err != nil {
   514  		res = append(res, err)
   515  	}
   516  
   517  	if err := m.contextValidateSize(ctx, formats); err != nil {
   518  		res = append(res, err)
   519  	}
   520  
   521  	if err := m.contextValidateURL(ctx, formats); err != nil {
   522  		res = append(res, err)
   523  	}
   524  
   525  	if len(res) > 0 {
   526  		return errors.CompositeValidationError(res...)
   527  	}
   528  	return nil
   529  }
   530  
   531  func (m *TaskAttachmentsAnon) contextValidateContentType(ctx context.Context, formats strfmt.Registry) error {
   532  
   533  	if err := validate.ReadOnly(ctx, "contentType", "body", string(m.ContentType)); err != nil {
   534  		return err
   535  	}
   536  
   537  	return nil
   538  }
   539  
   540  func (m *TaskAttachmentsAnon) contextValidateName(ctx context.Context, formats strfmt.Registry) error {
   541  
   542  	if err := validate.ReadOnly(ctx, "name", "body", string(m.Name)); err != nil {
   543  		return err
   544  	}
   545  
   546  	return nil
   547  }
   548  
   549  func (m *TaskAttachmentsAnon) contextValidateSize(ctx context.Context, formats strfmt.Registry) error {
   550  
   551  	if err := validate.ReadOnly(ctx, "size", "body", float64(m.Size)); err != nil {
   552  		return err
   553  	}
   554  
   555  	return nil
   556  }
   557  
   558  func (m *TaskAttachmentsAnon) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   559  
   560  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   561  		return err
   562  	}
   563  
   564  	return nil
   565  }
   566  
   567  // MarshalBinary interface implementation
   568  func (m *TaskAttachmentsAnon) MarshalBinary() ([]byte, error) {
   569  	if m == nil {
   570  		return nil, nil
   571  	}
   572  	return swag.WriteJSON(m)
   573  }
   574  
   575  // UnmarshalBinary interface implementation
   576  func (m *TaskAttachmentsAnon) UnmarshalBinary(b []byte) error {
   577  	var res TaskAttachmentsAnon
   578  	if err := swag.ReadJSON(b, &res); err != nil {
   579  		return err
   580  	}
   581  	*m = res
   582  	return nil
   583  }