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