github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/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  		if err := m.Stats.ContextValidate(ctx, formats); err != nil {
   144  			if ve, ok := err.(*errors.Validation); ok {
   145  				return ve.ValidateName("stats")
   146  			} else if ce, ok := err.(*errors.CompositeError); ok {
   147  				return ce.ValidateName("stats")
   148  			}
   149  			return err
   150  		}
   151  	}
   152  
   153  	return nil
   154  }
   155  
   156  // MarshalBinary interface implementation
   157  func (m *Milestone) MarshalBinary() ([]byte, error) {
   158  	if m == nil {
   159  		return nil, nil
   160  	}
   161  	return swag.WriteJSON(m)
   162  }
   163  
   164  // UnmarshalBinary interface implementation
   165  func (m *Milestone) UnmarshalBinary(b []byte) error {
   166  	var res Milestone
   167  	if err := swag.ReadJSON(b, &res); err != nil {
   168  		return err
   169  	}
   170  	*m = res
   171  	return nil
   172  }
   173  
   174  // MilestoneStats Some counters for this milestone.
   175  //
   176  // This object contains counts for the remaining open issues and the amount of issues that have been closed.
   177  //
   178  // swagger:model MilestoneStats
   179  type MilestoneStats struct {
   180  
   181  	// The closed issues.
   182  	Closed int32 `json:"closed,omitempty"`
   183  
   184  	// The remaining open issues.
   185  	Open int32 `json:"open,omitempty"`
   186  
   187  	// The total number of issues for this milestone.
   188  	Total int32 `json:"total,omitempty"`
   189  }
   190  
   191  // Validate validates this milestone stats
   192  func (m *MilestoneStats) Validate(formats strfmt.Registry) error {
   193  	return nil
   194  }
   195  
   196  // ContextValidate validates this milestone stats based on context it is used
   197  func (m *MilestoneStats) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   198  	return nil
   199  }
   200  
   201  // MarshalBinary interface implementation
   202  func (m *MilestoneStats) MarshalBinary() ([]byte, error) {
   203  	if m == nil {
   204  		return nil, nil
   205  	}
   206  	return swag.WriteJSON(m)
   207  }
   208  
   209  // UnmarshalBinary interface implementation
   210  func (m *MilestoneStats) UnmarshalBinary(b []byte) error {
   211  	var res MilestoneStats
   212  	if err := swag.ReadJSON(b, &res); err != nil {
   213  		return err
   214  	}
   215  	*m = res
   216  	return nil
   217  }