forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_card.go
143 lines (114 loc) · 3.43 KB
/
user_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
// 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 (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// UserCard A minimal representation of a user.
//
// This representation of a user is mainly meant for inclusion in other models, or for list views.
//
// swagger:model UserCard
type UserCard struct {
// When true this user is an admin.
//
// Only employees of the owning company can be admins.
// Admins are like project owners but have access to all the projects in the application.
// There aren't many admins, and it's only used for extremly critical issues with the application.
//
// Read Only: true
Admin *bool `json:"admin,omitempty"`
// The amount of karma this user has available.
//
// In this application users get a cerain amount of karma alotted.
// This karma can be donated to other users to show appreciation, or it can be used
// by a user to vote on issues.
// Once an issue is closed or rejected, the user gets his karma back.
//
// Read Only: true
// Maximum: < 1000
AvailableKarma float64 `json:"availableKarma,omitempty"`
// A unique identifier for a user.
//
// This id is automatically generated on the server when a user is created.
//
// Required: true
// Read Only: true
ID int64 `json:"id"`
// The screen name for the user.
//
// This is used for vanity type urls as well as login credentials.
//
// Required: true
// Max Length: 255
// Min Length: 3
// Pattern: \w[\w_-]+
ScreenName *string `json:"screenName"`
}
// Validate validates this user card
func (m *UserCard) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAvailableKarma(formats); err != nil {
res = append(res, err)
}
if err := m.validateID(formats); err != nil {
res = append(res, err)
}
if err := m.validateScreenName(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *UserCard) validateAvailableKarma(formats strfmt.Registry) error {
if swag.IsZero(m.AvailableKarma) { // not required
return nil
}
if err := validate.Maximum("availableKarma", "body", float64(m.AvailableKarma), 1000, true); err != nil {
return err
}
return nil
}
func (m *UserCard) validateID(formats strfmt.Registry) error {
if err := validate.Required("id", "body", int64(m.ID)); err != nil {
return err
}
return nil
}
func (m *UserCard) validateScreenName(formats strfmt.Registry) error {
if err := validate.Required("screenName", "body", m.ScreenName); err != nil {
return err
}
if err := validate.MinLength("screenName", "body", string(*m.ScreenName), 3); err != nil {
return err
}
if err := validate.MaxLength("screenName", "body", string(*m.ScreenName), 255); err != nil {
return err
}
if err := validate.Pattern("screenName", "body", string(*m.ScreenName), `\w[\w_-]+`); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *UserCard) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *UserCard) UnmarshalBinary(b []byte) error {
var res UserCard
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}