github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/models/comment.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  // Comment A comment for an issue.
    18  //
    19  // Users can comment on issues to discuss plans for resolution etc.
    20  //
    21  //
    22  // swagger:model Comment
    23  type Comment struct {
    24  
    25  	// The content of the comment.
    26  	//
    27  	// This is a free text field with support for github flavored markdown.
    28  	//
    29  	// Required: true
    30  	Content *string `json:"content"`
    31  
    32  	// The time at which this comment was created.
    33  	//
    34  	// This field is autogenerated when the content is posted.
    35  	// Read Only: true
    36  	// Format: date-time
    37  	CreatedAt strfmt.DateTime `json:"createdAt,omitempty"`
    38  
    39  	// user
    40  	// Required: true
    41  	User *UserCard `json:"user"`
    42  }
    43  
    44  // Validate validates this comment
    45  func (m *Comment) Validate(formats strfmt.Registry) error {
    46  	var res []error
    47  
    48  	if err := m.validateContent(formats); err != nil {
    49  		res = append(res, err)
    50  	}
    51  
    52  	if err := m.validateCreatedAt(formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  
    56  	if err := m.validateUser(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if len(res) > 0 {
    61  		return errors.CompositeValidationError(res...)
    62  	}
    63  	return nil
    64  }
    65  
    66  func (m *Comment) validateContent(formats strfmt.Registry) error {
    67  
    68  	if err := validate.Required("content", "body", m.Content); err != nil {
    69  		return err
    70  	}
    71  
    72  	return nil
    73  }
    74  
    75  func (m *Comment) validateCreatedAt(formats strfmt.Registry) error {
    76  	if swag.IsZero(m.CreatedAt) { // not required
    77  		return nil
    78  	}
    79  
    80  	if err := validate.FormatOf("createdAt", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
    81  		return err
    82  	}
    83  
    84  	return nil
    85  }
    86  
    87  func (m *Comment) validateUser(formats strfmt.Registry) error {
    88  
    89  	if err := validate.Required("user", "body", m.User); err != nil {
    90  		return err
    91  	}
    92  
    93  	if m.User != nil {
    94  		if err := m.User.Validate(formats); err != nil {
    95  			if ve, ok := err.(*errors.Validation); ok {
    96  				return ve.ValidateName("user")
    97  			} else if ce, ok := err.(*errors.CompositeError); ok {
    98  				return ce.ValidateName("user")
    99  			}
   100  			return err
   101  		}
   102  	}
   103  
   104  	return nil
   105  }
   106  
   107  // ContextValidate validate this comment based on the context it is used
   108  func (m *Comment) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   109  	var res []error
   110  
   111  	if err := m.contextValidateCreatedAt(ctx, formats); err != nil {
   112  		res = append(res, err)
   113  	}
   114  
   115  	if err := m.contextValidateUser(ctx, formats); err != nil {
   116  		res = append(res, err)
   117  	}
   118  
   119  	if len(res) > 0 {
   120  		return errors.CompositeValidationError(res...)
   121  	}
   122  	return nil
   123  }
   124  
   125  func (m *Comment) contextValidateCreatedAt(ctx context.Context, formats strfmt.Registry) error {
   126  
   127  	if err := validate.ReadOnly(ctx, "createdAt", "body", strfmt.DateTime(m.CreatedAt)); err != nil {
   128  		return err
   129  	}
   130  
   131  	return nil
   132  }
   133  
   134  func (m *Comment) contextValidateUser(ctx context.Context, formats strfmt.Registry) error {
   135  
   136  	if m.User != nil {
   137  		if err := m.User.ContextValidate(ctx, formats); err != nil {
   138  			if ve, ok := err.(*errors.Validation); ok {
   139  				return ve.ValidateName("user")
   140  			} else if ce, ok := err.(*errors.CompositeError); ok {
   141  				return ce.ValidateName("user")
   142  			}
   143  			return err
   144  		}
   145  	}
   146  
   147  	return nil
   148  }
   149  
   150  // MarshalBinary interface implementation
   151  func (m *Comment) MarshalBinary() ([]byte, error) {
   152  	if m == nil {
   153  		return nil, nil
   154  	}
   155  	return swag.WriteJSON(m)
   156  }
   157  
   158  // UnmarshalBinary interface implementation
   159  func (m *Comment) UnmarshalBinary(b []byte) error {
   160  	var res Comment
   161  	if err := swag.ReadJSON(b, &res); err != nil {
   162  		return err
   163  	}
   164  	*m = res
   165  	return nil
   166  }