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