github.com/dirkm/go-swagger@v0.19.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  	strfmt "github.com/go-openapi/strfmt"
    10  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/swag"
    13  	"github.com/go-openapi/validate"
    14  )
    15  
    16  // Milestone A milestone is a particular goal that is important to the project for this issue tracker.
    17  //
    18  // Milestones can have a escription and due date.
    19  // This can be useful for filters and such.
    20  //
    21  // swagger:model Milestone
    22  type Milestone struct {
    23  
    24  	// The description of the milestone.
    25  	//
    26  	// A description is a free text field that allows for a more detailed explanation of what the milestone is trying to achieve.
    27  	//
    28  	Description string `json:"description,omitempty"`
    29  
    30  	// An optional due date for this milestone.
    31  	//
    32  	// This property is optional, but when present it lets people know when they can expect this milestone to be completed.
    33  	//
    34  	// Format: date
    35  	DueDate strfmt.Date `json:"dueDate,omitempty"`
    36  
    37  	// The name of the milestone.
    38  	//
    39  	// Each milestone should get a unique name.
    40  	//
    41  	// Required: true
    42  	// Max Length: 50
    43  	// Min Length: 3
    44  	// Pattern: [A-Za-z][\w- ]+
    45  	Name *string `json:"name"`
    46  
    47  	// stats
    48  	Stats *MilestoneStats `json:"stats,omitempty"`
    49  }
    50  
    51  // Validate validates this milestone
    52  func (m *Milestone) Validate(formats strfmt.Registry) error {
    53  	var res []error
    54  
    55  	if err := m.validateDueDate(formats); err != nil {
    56  		res = append(res, err)
    57  	}
    58  
    59  	if err := m.validateName(formats); err != nil {
    60  		res = append(res, err)
    61  	}
    62  
    63  	if err := m.validateStats(formats); err != nil {
    64  		res = append(res, err)
    65  	}
    66  
    67  	if len(res) > 0 {
    68  		return errors.CompositeValidationError(res...)
    69  	}
    70  	return nil
    71  }
    72  
    73  func (m *Milestone) validateDueDate(formats strfmt.Registry) error {
    74  
    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", string(*m.Name), 3); err != nil {
    93  		return err
    94  	}
    95  
    96  	if err := validate.MaxLength("name", "body", string(*m.Name), 50); err != nil {
    97  		return err
    98  	}
    99  
   100  	if err := validate.Pattern("name", "body", string(*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  
   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  			}
   118  			return err
   119  		}
   120  	}
   121  
   122  	return nil
   123  }
   124  
   125  // MarshalBinary interface implementation
   126  func (m *Milestone) MarshalBinary() ([]byte, error) {
   127  	if m == nil {
   128  		return nil, nil
   129  	}
   130  	return swag.WriteJSON(m)
   131  }
   132  
   133  // UnmarshalBinary interface implementation
   134  func (m *Milestone) UnmarshalBinary(b []byte) error {
   135  	var res Milestone
   136  	if err := swag.ReadJSON(b, &res); err != nil {
   137  		return err
   138  	}
   139  	*m = res
   140  	return nil
   141  }
   142  
   143  // MilestoneStats Some counters for this milestone.
   144  //
   145  // This object contains counts for the remaining open issues and the amount of issues that have been closed.
   146  //
   147  // swagger:model MilestoneStats
   148  type MilestoneStats struct {
   149  
   150  	// The closed issues.
   151  	Closed int32 `json:"closed,omitempty"`
   152  
   153  	// The remaining open issues.
   154  	Open int32 `json:"open,omitempty"`
   155  
   156  	// The total number of issues for this milestone.
   157  	Total int32 `json:"total,omitempty"`
   158  }
   159  
   160  // Validate validates this milestone stats
   161  func (m *MilestoneStats) Validate(formats strfmt.Registry) error {
   162  	return nil
   163  }
   164  
   165  // MarshalBinary interface implementation
   166  func (m *MilestoneStats) MarshalBinary() ([]byte, error) {
   167  	if m == nil {
   168  		return nil, nil
   169  	}
   170  	return swag.WriteJSON(m)
   171  }
   172  
   173  // UnmarshalBinary interface implementation
   174  func (m *MilestoneStats) UnmarshalBinary(b []byte) error {
   175  	var res MilestoneStats
   176  	if err := swag.ReadJSON(b, &res); err != nil {
   177  		return err
   178  	}
   179  	*m = res
   180  	return nil
   181  }