github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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/go-openapi/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 // swagger:model Comment 22 type Comment struct { 23 24 // The content of the comment. 25 // 26 // This is a free text field with support for github flavored markdown. 27 // 28 // Required: true 29 Content *string `json:"content"` 30 31 // The time at which this comment was created. 32 // 33 // This field is autogenerated when the content is posted. 34 // Read Only: true 35 // Format: date-time 36 CreatedAt strfmt.DateTime `json:"createdAt,omitempty"` 37 38 // user 39 // Required: true 40 User *UserCard `json:"user"` 41 } 42 43 // Validate validates this comment 44 func (m *Comment) Validate(formats strfmt.Registry) error { 45 var res []error 46 47 if err := m.validateContent(formats); err != nil { 48 res = append(res, err) 49 } 50 51 if err := m.validateCreatedAt(formats); err != nil { 52 res = append(res, err) 53 } 54 55 if err := m.validateUser(formats); err != nil { 56 res = append(res, err) 57 } 58 59 if len(res) > 0 { 60 return errors.CompositeValidationError(res...) 61 } 62 return nil 63 } 64 65 func (m *Comment) validateContent(formats strfmt.Registry) error { 66 67 if err := validate.Required("content", "body", m.Content); err != nil { 68 return err 69 } 70 71 return nil 72 } 73 74 func (m *Comment) validateCreatedAt(formats strfmt.Registry) error { 75 if swag.IsZero(m.CreatedAt) { // not required 76 return nil 77 } 78 79 if err := validate.FormatOf("createdAt", "body", "date-time", m.CreatedAt.String(), formats); err != nil { 80 return err 81 } 82 83 return nil 84 } 85 86 func (m *Comment) validateUser(formats strfmt.Registry) error { 87 88 if err := validate.Required("user", "body", m.User); err != nil { 89 return err 90 } 91 92 if m.User != nil { 93 if err := m.User.Validate(formats); err != nil { 94 if ve, ok := err.(*errors.Validation); ok { 95 return ve.ValidateName("user") 96 } else if ce, ok := err.(*errors.CompositeError); ok { 97 return ce.ValidateName("user") 98 } 99 return err 100 } 101 } 102 103 return nil 104 } 105 106 // ContextValidate validate this comment based on the context it is used 107 func (m *Comment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 108 var res []error 109 110 if err := m.contextValidateCreatedAt(ctx, formats); err != nil { 111 res = append(res, err) 112 } 113 114 if err := m.contextValidateUser(ctx, formats); err != nil { 115 res = append(res, err) 116 } 117 118 if len(res) > 0 { 119 return errors.CompositeValidationError(res...) 120 } 121 return nil 122 } 123 124 func (m *Comment) contextValidateCreatedAt(ctx context.Context, formats strfmt.Registry) error { 125 126 if err := validate.ReadOnly(ctx, "createdAt", "body", strfmt.DateTime(m.CreatedAt)); err != nil { 127 return err 128 } 129 130 return nil 131 } 132 133 func (m *Comment) contextValidateUser(ctx context.Context, formats strfmt.Registry) error { 134 135 if m.User != nil { 136 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 }