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