github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/models/task.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 "strconv" 10 11 strfmt "github.com/go-openapi/strfmt" 12 13 "github.com/go-openapi/errors" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Task a structure describing a complete task. 19 // 20 // A Task is the main entity in this application. Everything revolves around tasks and managing them. 21 // 22 // swagger:model Task 23 type Task struct { 24 TaskCard 25 26 // The attached files. 27 // 28 // An issue can have at most 20 files attached to it. 29 // 30 Attachments map[string]TaskAttachmentsAnon `json:"attachments,omitempty"` 31 32 // The 5 most recent items for this issue. 33 // 34 // The detail view of an issue includes the 5 most recent comments. 35 // This field is read only, comments are added through a separate process. 36 // 37 // Read Only: true 38 Comments []*Comment `json:"comments"` 39 40 // The time at which this issue was last updated. 41 // 42 // This field is read only so it's only sent as part of the response. 43 // 44 // Read Only: true 45 // Format: date-time 46 LastUpdated strfmt.DateTime `json:"lastUpdated,omitempty"` 47 48 // last updated by 49 LastUpdatedBy *UserCard `json:"lastUpdatedBy,omitempty"` 50 51 // reported by 52 ReportedBy *UserCard `json:"reportedBy,omitempty"` 53 } 54 55 // UnmarshalJSON unmarshals this object from a JSON structure 56 func (m *Task) UnmarshalJSON(raw []byte) error { 57 // AO0 58 var aO0 TaskCard 59 if err := swag.ReadJSON(raw, &aO0); err != nil { 60 return err 61 } 62 m.TaskCard = aO0 63 64 // AO1 65 var dataAO1 struct { 66 Attachments map[string]TaskAttachmentsAnon `json:"attachments,omitempty"` 67 68 Comments []*Comment `json:"comments"` 69 70 LastUpdated strfmt.DateTime `json:"lastUpdated,omitempty"` 71 72 LastUpdatedBy *UserCard `json:"lastUpdatedBy,omitempty"` 73 74 ReportedBy *UserCard `json:"reportedBy,omitempty"` 75 } 76 if err := swag.ReadJSON(raw, &dataAO1); err != nil { 77 return err 78 } 79 80 m.Attachments = dataAO1.Attachments 81 82 m.Comments = dataAO1.Comments 83 84 m.LastUpdated = dataAO1.LastUpdated 85 86 m.LastUpdatedBy = dataAO1.LastUpdatedBy 87 88 m.ReportedBy = dataAO1.ReportedBy 89 90 return nil 91 } 92 93 // MarshalJSON marshals this object to a JSON structure 94 func (m Task) MarshalJSON() ([]byte, error) { 95 _parts := make([][]byte, 0, 2) 96 97 aO0, err := swag.WriteJSON(m.TaskCard) 98 if err != nil { 99 return nil, err 100 } 101 _parts = append(_parts, aO0) 102 103 var dataAO1 struct { 104 Attachments map[string]TaskAttachmentsAnon `json:"attachments,omitempty"` 105 106 Comments []*Comment `json:"comments"` 107 108 LastUpdated strfmt.DateTime `json:"lastUpdated,omitempty"` 109 110 LastUpdatedBy *UserCard `json:"lastUpdatedBy,omitempty"` 111 112 ReportedBy *UserCard `json:"reportedBy,omitempty"` 113 } 114 115 dataAO1.Attachments = m.Attachments 116 117 dataAO1.Comments = m.Comments 118 119 dataAO1.LastUpdated = m.LastUpdated 120 121 dataAO1.LastUpdatedBy = m.LastUpdatedBy 122 123 dataAO1.ReportedBy = m.ReportedBy 124 125 jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) 126 if errAO1 != nil { 127 return nil, errAO1 128 } 129 _parts = append(_parts, jsonDataAO1) 130 131 return swag.ConcatJSON(_parts...), nil 132 } 133 134 // Validate validates this task 135 func (m *Task) Validate(formats strfmt.Registry) error { 136 var res []error 137 138 // validation for a type composition with TaskCard 139 if err := m.TaskCard.Validate(formats); err != nil { 140 res = append(res, err) 141 } 142 143 if err := m.validateAttachments(formats); err != nil { 144 res = append(res, err) 145 } 146 147 if err := m.validateComments(formats); err != nil { 148 res = append(res, err) 149 } 150 151 if err := m.validateLastUpdated(formats); err != nil { 152 res = append(res, err) 153 } 154 155 if err := m.validateLastUpdatedBy(formats); err != nil { 156 res = append(res, err) 157 } 158 159 if err := m.validateReportedBy(formats); err != nil { 160 res = append(res, err) 161 } 162 163 if len(res) > 0 { 164 return errors.CompositeValidationError(res...) 165 } 166 return nil 167 } 168 169 func (m *Task) validateAttachments(formats strfmt.Registry) error { 170 171 if swag.IsZero(m.Attachments) { // not required 172 return nil 173 } 174 175 for k := range m.Attachments { 176 177 if swag.IsZero(m.Attachments[k]) { // not required 178 continue 179 } 180 if val, ok := m.Attachments[k]; ok { 181 if err := val.Validate(formats); err != nil { 182 return err 183 } 184 } 185 186 } 187 188 return nil 189 } 190 191 func (m *Task) validateComments(formats strfmt.Registry) error { 192 193 if swag.IsZero(m.Comments) { // not required 194 return nil 195 } 196 197 for i := 0; i < len(m.Comments); i++ { 198 if swag.IsZero(m.Comments[i]) { // not required 199 continue 200 } 201 202 if m.Comments[i] != nil { 203 if err := m.Comments[i].Validate(formats); err != nil { 204 if ve, ok := err.(*errors.Validation); ok { 205 return ve.ValidateName("comments" + "." + strconv.Itoa(i)) 206 } 207 return err 208 } 209 } 210 211 } 212 213 return nil 214 } 215 216 func (m *Task) validateLastUpdated(formats strfmt.Registry) error { 217 218 if swag.IsZero(m.LastUpdated) { // not required 219 return nil 220 } 221 222 if err := validate.FormatOf("lastUpdated", "body", "date-time", m.LastUpdated.String(), formats); err != nil { 223 return err 224 } 225 226 return nil 227 } 228 229 func (m *Task) validateLastUpdatedBy(formats strfmt.Registry) error { 230 231 if swag.IsZero(m.LastUpdatedBy) { // not required 232 return nil 233 } 234 235 if m.LastUpdatedBy != nil { 236 if err := m.LastUpdatedBy.Validate(formats); err != nil { 237 if ve, ok := err.(*errors.Validation); ok { 238 return ve.ValidateName("lastUpdatedBy") 239 } 240 return err 241 } 242 } 243 244 return nil 245 } 246 247 func (m *Task) validateReportedBy(formats strfmt.Registry) error { 248 249 if swag.IsZero(m.ReportedBy) { // not required 250 return nil 251 } 252 253 if m.ReportedBy != nil { 254 if err := m.ReportedBy.Validate(formats); err != nil { 255 if ve, ok := err.(*errors.Validation); ok { 256 return ve.ValidateName("reportedBy") 257 } 258 return err 259 } 260 } 261 262 return nil 263 } 264 265 // MarshalBinary interface implementation 266 func (m *Task) MarshalBinary() ([]byte, error) { 267 if m == nil { 268 return nil, nil 269 } 270 return swag.WriteJSON(m) 271 } 272 273 // UnmarshalBinary interface implementation 274 func (m *Task) UnmarshalBinary(b []byte) error { 275 var res Task 276 if err := swag.ReadJSON(b, &res); err != nil { 277 return err 278 } 279 *m = res 280 return nil 281 } 282 283 // TaskAttachmentsAnon task attachments anon 284 // swagger:model TaskAttachmentsAnon 285 type TaskAttachmentsAnon struct { 286 287 // The content type of the file. 288 // 289 // The content type of the file is inferred from the upload request. 290 // 291 // Read Only: true 292 ContentType string `json:"contentType,omitempty"` 293 294 // Extra information to attach to the file. 295 // 296 // This is a free form text field with support for github flavored markdown. 297 // 298 // Min Length: 3 299 Description string `json:"description,omitempty"` 300 301 // The name of the file. 302 // 303 // This name is inferred from the upload request. 304 // 305 // Read Only: true 306 Name string `json:"name,omitempty"` 307 308 // The file size in bytes. 309 // 310 // This property was generated during the upload request of the file. 311 // Read Only: true 312 Size float64 `json:"size,omitempty"` 313 314 // The url to download or view the file. 315 // 316 // This URL is generated on the server, based on where it was able to store the file when it was uploaded. 317 // 318 // Read Only: true 319 // Format: uri 320 URL strfmt.URI `json:"url,omitempty"` 321 } 322 323 // Validate validates this task attachments anon 324 func (m *TaskAttachmentsAnon) Validate(formats strfmt.Registry) error { 325 var res []error 326 327 if err := m.validateDescription(formats); err != nil { 328 res = append(res, err) 329 } 330 331 if err := m.validateURL(formats); err != nil { 332 res = append(res, err) 333 } 334 335 if len(res) > 0 { 336 return errors.CompositeValidationError(res...) 337 } 338 return nil 339 } 340 341 func (m *TaskAttachmentsAnon) validateDescription(formats strfmt.Registry) error { 342 343 if swag.IsZero(m.Description) { // not required 344 return nil 345 } 346 347 if err := validate.MinLength("description", "body", string(m.Description), 3); err != nil { 348 return err 349 } 350 351 return nil 352 } 353 354 func (m *TaskAttachmentsAnon) validateURL(formats strfmt.Registry) error { 355 356 if swag.IsZero(m.URL) { // not required 357 return nil 358 } 359 360 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 361 return err 362 } 363 364 return nil 365 } 366 367 // MarshalBinary interface implementation 368 func (m *TaskAttachmentsAnon) MarshalBinary() ([]byte, error) { 369 if m == nil { 370 return nil, nil 371 } 372 return swag.WriteJSON(m) 373 } 374 375 // UnmarshalBinary interface implementation 376 func (m *TaskAttachmentsAnon) UnmarshalBinary(b []byte) error { 377 var res TaskAttachmentsAnon 378 if err := swag.ReadJSON(b, &res); err != nil { 379 return err 380 } 381 *m = res 382 return nil 383 }