github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/models/task_card.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 "encoding/json" 10 "strconv" 11 12 strfmt "github.com/go-openapi/strfmt" 13 14 "github.com/go-openapi/errors" 15 "github.com/go-openapi/swag" 16 "github.com/go-openapi/validate" 17 ) 18 19 // TaskCard a card for a task 20 // 21 // A task card is a minimalistic representation of a task. Useful for display in list views, like a card list. 22 // 23 // swagger:model TaskCard 24 type TaskCard struct { 25 26 // assigned to 27 AssignedTo *UserCard `json:"assignedTo,omitempty"` 28 29 // The description of the task. 30 // 31 // The task description is a longer, more detailed description of the issue. 32 // Perhaps it even mentions steps to reproduce. 33 // 34 Description string `json:"description,omitempty"` 35 36 // the level of effort required to get this task completed 37 // Maximum: 27 38 // Multiple Of: 3 39 Effort int32 `json:"effort,omitempty"` 40 41 // The id of the task. 42 // 43 // A unique identifier for the task. These are created in ascending order. 44 // Read Only: true 45 ID int64 `json:"id,omitempty"` 46 47 // the karma donated to this item. 48 // 49 // Karma is a lot like voting. Users can donate a certain amount or karma to an issue. 50 // This is used to determine the weight users place on an issue. Not that +1 comments aren't great. 51 // 52 // Minimum: > 0 53 // Multiple Of: 0.5 54 Karma float64 `json:"karma,omitempty"` 55 56 // milestone 57 Milestone *Milestone `json:"milestone,omitempty"` 58 59 // The time at which this issue was reported. 60 // 61 // This field is read-only, so it's only sent as part of the response. 62 // 63 // Read Only: true 64 // Format: date-time 65 ReportedAt strfmt.DateTime `json:"reportedAt,omitempty"` 66 67 // severity 68 // Maximum: 5 69 // Minimum: 1 70 Severity int32 `json:"severity,omitempty"` 71 72 // the status of the issue 73 // 74 // There are 4 possible values for a status. 75 // Ignored means as much as accepted but not now, perhaps later. 76 // 77 // Required: true 78 // Enum: [open closed ignored rejected] 79 Status *string `json:"status"` 80 81 // task tags. 82 // 83 // a task can be tagged with text blurbs. 84 // Max Items: 5 85 // Unique: true 86 Tags []string `json:"tags"` 87 88 // The title of the task. 89 // 90 // The title for a task, this needs to be at least 5 chars long. 91 // Titles don't allow any formatting, besides emoji. 92 // 93 // Required: true 94 // Max Length: 150 95 // Min Length: 5 96 Title *string `json:"title"` 97 } 98 99 // Validate validates this task card 100 func (m *TaskCard) Validate(formats strfmt.Registry) error { 101 var res []error 102 103 if err := m.validateAssignedTo(formats); err != nil { 104 res = append(res, err) 105 } 106 107 if err := m.validateEffort(formats); err != nil { 108 res = append(res, err) 109 } 110 111 if err := m.validateKarma(formats); err != nil { 112 res = append(res, err) 113 } 114 115 if err := m.validateMilestone(formats); err != nil { 116 res = append(res, err) 117 } 118 119 if err := m.validateReportedAt(formats); err != nil { 120 res = append(res, err) 121 } 122 123 if err := m.validateSeverity(formats); err != nil { 124 res = append(res, err) 125 } 126 127 if err := m.validateStatus(formats); err != nil { 128 res = append(res, err) 129 } 130 131 if err := m.validateTags(formats); err != nil { 132 res = append(res, err) 133 } 134 135 if err := m.validateTitle(formats); err != nil { 136 res = append(res, err) 137 } 138 139 if len(res) > 0 { 140 return errors.CompositeValidationError(res...) 141 } 142 return nil 143 } 144 145 func (m *TaskCard) validateAssignedTo(formats strfmt.Registry) error { 146 147 if swag.IsZero(m.AssignedTo) { // not required 148 return nil 149 } 150 151 if m.AssignedTo != nil { 152 if err := m.AssignedTo.Validate(formats); err != nil { 153 if ve, ok := err.(*errors.Validation); ok { 154 return ve.ValidateName("assignedTo") 155 } 156 return err 157 } 158 } 159 160 return nil 161 } 162 163 func (m *TaskCard) validateEffort(formats strfmt.Registry) error { 164 165 if swag.IsZero(m.Effort) { // not required 166 return nil 167 } 168 169 if err := validate.MaximumInt("effort", "body", int64(m.Effort), 27, false); err != nil { 170 return err 171 } 172 173 if err := validate.MultipleOf("effort", "body", float64(m.Effort), 3); err != nil { 174 return err 175 } 176 177 return nil 178 } 179 180 func (m *TaskCard) validateKarma(formats strfmt.Registry) error { 181 182 if swag.IsZero(m.Karma) { // not required 183 return nil 184 } 185 186 if err := validate.Minimum("karma", "body", float64(m.Karma), 0, true); err != nil { 187 return err 188 } 189 190 if err := validate.MultipleOf("karma", "body", float64(m.Karma), 0.5); err != nil { 191 return err 192 } 193 194 return nil 195 } 196 197 func (m *TaskCard) validateMilestone(formats strfmt.Registry) error { 198 199 if swag.IsZero(m.Milestone) { // not required 200 return nil 201 } 202 203 if m.Milestone != nil { 204 if err := m.Milestone.Validate(formats); err != nil { 205 if ve, ok := err.(*errors.Validation); ok { 206 return ve.ValidateName("milestone") 207 } 208 return err 209 } 210 } 211 212 return nil 213 } 214 215 func (m *TaskCard) validateReportedAt(formats strfmt.Registry) error { 216 217 if swag.IsZero(m.ReportedAt) { // not required 218 return nil 219 } 220 221 if err := validate.FormatOf("reportedAt", "body", "date-time", m.ReportedAt.String(), formats); err != nil { 222 return err 223 } 224 225 return nil 226 } 227 228 func (m *TaskCard) validateSeverity(formats strfmt.Registry) error { 229 230 if swag.IsZero(m.Severity) { // not required 231 return nil 232 } 233 234 if err := validate.MinimumInt("severity", "body", int64(m.Severity), 1, false); err != nil { 235 return err 236 } 237 238 if err := validate.MaximumInt("severity", "body", int64(m.Severity), 5, false); err != nil { 239 return err 240 } 241 242 return nil 243 } 244 245 var taskCardTypeStatusPropEnum []interface{} 246 247 func init() { 248 var res []string 249 if err := json.Unmarshal([]byte(`["open","closed","ignored","rejected"]`), &res); err != nil { 250 panic(err) 251 } 252 for _, v := range res { 253 taskCardTypeStatusPropEnum = append(taskCardTypeStatusPropEnum, v) 254 } 255 } 256 257 const ( 258 259 // TaskCardStatusOpen captures enum value "open" 260 TaskCardStatusOpen string = "open" 261 262 // TaskCardStatusClosed captures enum value "closed" 263 TaskCardStatusClosed string = "closed" 264 265 // TaskCardStatusIgnored captures enum value "ignored" 266 TaskCardStatusIgnored string = "ignored" 267 268 // TaskCardStatusRejected captures enum value "rejected" 269 TaskCardStatusRejected string = "rejected" 270 ) 271 272 // prop value enum 273 func (m *TaskCard) validateStatusEnum(path, location string, value string) error { 274 if err := validate.Enum(path, location, value, taskCardTypeStatusPropEnum); err != nil { 275 return err 276 } 277 return nil 278 } 279 280 func (m *TaskCard) validateStatus(formats strfmt.Registry) error { 281 282 if err := validate.Required("status", "body", m.Status); err != nil { 283 return err 284 } 285 286 // value enum 287 if err := m.validateStatusEnum("status", "body", *m.Status); err != nil { 288 return err 289 } 290 291 return nil 292 } 293 294 func (m *TaskCard) validateTags(formats strfmt.Registry) error { 295 296 if swag.IsZero(m.Tags) { // not required 297 return nil 298 } 299 300 iTagsSize := int64(len(m.Tags)) 301 302 if err := validate.MaxItems("tags", "body", iTagsSize, 5); err != nil { 303 return err 304 } 305 306 if err := validate.UniqueItems("tags", "body", m.Tags); err != nil { 307 return err 308 } 309 310 for i := 0; i < len(m.Tags); i++ { 311 312 if err := validate.MinLength("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i]), 3); err != nil { 313 return err 314 } 315 316 if err := validate.Pattern("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i]), `\w[\w- ]+`); err != nil { 317 return err 318 } 319 320 } 321 322 return nil 323 } 324 325 func (m *TaskCard) validateTitle(formats strfmt.Registry) error { 326 327 if err := validate.Required("title", "body", m.Title); err != nil { 328 return err 329 } 330 331 if err := validate.MinLength("title", "body", string(*m.Title), 5); err != nil { 332 return err 333 } 334 335 if err := validate.MaxLength("title", "body", string(*m.Title), 150); err != nil { 336 return err 337 } 338 339 return nil 340 } 341 342 // MarshalBinary interface implementation 343 func (m *TaskCard) MarshalBinary() ([]byte, error) { 344 if m == nil { 345 return nil, nil 346 } 347 return swag.WriteJSON(m) 348 } 349 350 // UnmarshalBinary interface implementation 351 func (m *TaskCard) UnmarshalBinary(b []byte) error { 352 var res TaskCard 353 if err := swag.ReadJSON(b, &res); err != nil { 354 return err 355 } 356 *m = res 357 return nil 358 }