github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/models/milestone.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  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/go-openapi/swag"
    14  	"github.com/go-openapi/validate"
    15  )
    16  
    17  // Milestone A milestone is a particular goal that is important to the project for this issue tracker.
    18  //
    19  // Milestones can have a escription and due date.
    20  // This can be useful for filters and such.
    21  //
    22  // swagger:model Milestone
    23  type Milestone struct {
    24  
    25  	// The description of the milestone.
    26  	//
    27  	// A description is a free text field that allows for a more detailed explanation of what the milestone is trying to achieve.
    28  	//
    29  	Description string `json:"description,omitempty"`
    30  
    31  	// An optional due date for this milestone.
    32  	//
    33  	// This property is optional, but when present it lets people know when they can expect this milestone to be completed.
    34  	//
    35  	// Format: date
    36  	DueDate strfmt.Date `json:"dueDate,omitempty"`
    37  
    38  	// The name of the milestone.
    39  	//
    40  	// Each milestone should get a unique name.
    41  	//
    42  	// Required: true
    43  	// Max Length: 50
    44  	// Min Length: 3
    45  	// Pattern: [A-Za-z][\w- ]+
    46  	Name *string `json:"name"`
    47  
    48  	// stats
    49  	Stats *MilestoneStats `json:"stats,omitempty"`
    50  }
    51  
    52  // Validate validates this milestone
    53  func (m *Milestone) Validate(formats strfmt.Registry) error {
    54  	var res []error
    55  
    56  	if err := m.validateDueDate(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if err := m.validateName(formats); err != nil {
    61  		res = append(res, err)
    62  	}
    63  
    64  	if err := m.validateStats(formats); err != nil {
    65  		res = append(res, err)
    66  	}
    67  
    68  	if len(res) > 0 {
    69  		return errors.CompositeValidationError(res...)
    70  	}
    71  	return nil
    72  }
    73  
    74  func (m *Milestone) validateDueDate(formats strfmt.Registry) error {
    75  	if swag.IsZero(m.DueDate) { // not required
    76  		return nil
    77  	}
    78  
    79  	if err := validate.FormatOf("dueDate", "body", "date", m.DueDate.String(), formats); err != nil {
    80  		return err
    81  	}
    82  
    83  	return nil
    84  }
    85  
    86  func (m *Milestone) validateName(formats strfmt.Registry) error {
    87  
    88  	if err := validate.Required("name", "body", m.Name); err != nil {
    89  		return err
    90  	}
    91  
    92  	if err := validate.MinLength("name", "body", *m.Name, 3); err != nil {
    93  		return err
    94  	}
    95  
    96  	if err := validate.MaxLength("name", "body", *m.Name, 50); err != nil {
    97  		return err
    98  	}
    99  
   100  	if err := validate.Pattern("name", "body", *m.Name, `[A-Za-z][\w- ]+`); err != nil {
   101  		return err
   102  	}
   103  
   104  	return nil
   105  }
   106  
   107  func (m *Milestone) validateStats(formats strfmt.Registry) error {
   108  	if swag.IsZero(m.Stats) { // not required
   109  		return nil
   110  	}
   111  
   112  	if m.Stats != nil {
   113  		if err := m.Stats.Validate(formats); err != nil {
   114  			if ve, ok := err.(*errors.Validation); ok {
   115  				return ve.ValidateName("stats")
   116  			} else if ce, ok := err.(*errors.CompositeError); ok {
   117  				return ce.ValidateName("stats")
   118  			}
   119  			return err
   120  		}
   121  	}
   122  
   123  	return nil
   124  }
   125  
   126  // ContextValidate validate this milestone based on the context it is used
   127  func (m *Milestone) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   128  	var res []error
   129  
   130  	if err := m.contextValidateStats(ctx, formats); err != nil {
   131  		res = append(res, err)
   132  	}
   133  
   134  	if len(res) > 0 {
   135  		return errors.CompositeValidationError(res...)
   136  	}
   137  	return nil
   138  }
   139  
   140  func (m *Milestone) contextValidateStats(ctx context.Context, formats strfmt.Registry) error {
   141  
   142  	if m.Stats != nil {
   143  
   144  		if swag.IsZero(m.Stats) { // not required
   145  			return nil
   146  		}
   147  
   148  		if err := m.Stats.ContextValidate(ctx, formats); err != nil {
   149  			if ve, ok := err.(*errors.Validation); ok {
   150  				return ve.ValidateName("stats")
   151  			} else if ce, ok := err.(*errors.CompositeError); ok {
   152  				return ce.ValidateName("stats")
   153  			}
   154  			return err
   155  		}
   156  	}
   157  
   158  	return nil
   159  }
   160  
   161  // MarshalBinary interface implementation
   162  func (m *Milestone) MarshalBinary() ([]byte, error) {
   163  	if m == nil {
   164  		return nil, nil
   165  	}
   166  	return swag.WriteJSON(m)
   167  }
   168  
   169  // UnmarshalBinary interface implementation
   170  func (m *Milestone) UnmarshalBinary(b []byte) error {
   171  	var res Milestone
   172  	if err := swag.ReadJSON(b, &res); err != nil {
   173  		return err
   174  	}
   175  	*m = res
   176  	return nil
   177  }
   178  
   179  // MilestoneStats Some counters for this milestone.
   180  //
   181  // This object contains counts for the remaining open issues and the amount of issues that have been closed.
   182  //
   183  // swagger:model MilestoneStats
   184  type MilestoneStats struct {
   185  
   186  	// The closed issues.
   187  	Closed int32 `json:"closed,omitempty"`
   188  
   189  	// The remaining open issues.
   190  	Open int32 `json:"open,omitempty"`
   191  
   192  	// The total number of issues for this milestone.
   193  	Total int32 `json:"total,omitempty"`
   194  }
   195  
   196  // Validate validates this milestone stats
   197  func (m *MilestoneStats) Validate(formats strfmt.Registry) error {
   198  	return nil
   199  }
   200  
   201  // ContextValidate validates this milestone stats based on context it is used
   202  func (m *MilestoneStats) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   203  	return nil
   204  }
   205  
   206  // MarshalBinary interface implementation
   207  func (m *MilestoneStats) MarshalBinary() ([]byte, error) {
   208  	if m == nil {
   209  		return nil, nil
   210  	}
   211  	return swag.WriteJSON(m)
   212  }
   213  
   214  // UnmarshalBinary interface implementation
   215  func (m *MilestoneStats) UnmarshalBinary(b []byte) error {
   216  	var res MilestoneStats
   217  	if err := swag.ReadJSON(b, &res); err != nil {
   218  		return err
   219  	}
   220  	*m = res
   221  	return nil
   222  }