github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/models/user_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 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/strfmt" 13 "github.com/go-openapi/swag" 14 "github.com/go-openapi/validate" 15 ) 16 17 // UserCard A minimal representation of a user. 18 // 19 // This representation of a user is mainly meant for inclusion in other models, or for list views. 20 // 21 // swagger:model UserCard 22 type UserCard struct { 23 24 // When true this user is an admin. 25 // 26 // Only employees of the owning company can be admins. 27 // Admins are like project owners but have access to all the projects in the application. 28 // There aren't many admins, and it's only used for extremly critical issues with the application. 29 // 30 // Read Only: true 31 Admin *bool `json:"admin,omitempty"` 32 33 // The amount of karma this user has available. 34 // 35 // In this application users get a cerain amount of karma alotted. 36 // This karma can be donated to other users to show appreciation, or it can be used 37 // by a user to vote on issues. 38 // Once an issue is closed or rejected, the user gets his karma back. 39 // 40 // Read Only: true 41 // Maximum: < 1000 42 AvailableKarma float64 `json:"availableKarma,omitempty"` 43 44 // A unique identifier for a user. 45 // 46 // This id is automatically generated on the server when a user is created. 47 // 48 // Required: true 49 // Read Only: true 50 ID int64 `json:"id"` 51 52 // The screen name for the user. 53 // 54 // This is used for vanity type urls as well as login credentials. 55 // 56 // Required: true 57 // Max Length: 255 58 // Min Length: 3 59 // Pattern: \w[\w_-]+ 60 ScreenName *string `json:"screenName"` 61 } 62 63 // Validate validates this user card 64 func (m *UserCard) Validate(formats strfmt.Registry) error { 65 var res []error 66 67 if err := m.validateAvailableKarma(formats); err != nil { 68 res = append(res, err) 69 } 70 71 if err := m.validateID(formats); err != nil { 72 res = append(res, err) 73 } 74 75 if err := m.validateScreenName(formats); err != nil { 76 res = append(res, err) 77 } 78 79 if len(res) > 0 { 80 return errors.CompositeValidationError(res...) 81 } 82 return nil 83 } 84 85 func (m *UserCard) validateAvailableKarma(formats strfmt.Registry) error { 86 if swag.IsZero(m.AvailableKarma) { // not required 87 return nil 88 } 89 90 if err := validate.Maximum("availableKarma", "body", m.AvailableKarma, 1000, true); err != nil { 91 return err 92 } 93 94 return nil 95 } 96 97 func (m *UserCard) validateID(formats strfmt.Registry) error { 98 99 if err := validate.Required("id", "body", int64(m.ID)); err != nil { 100 return err 101 } 102 103 return nil 104 } 105 106 func (m *UserCard) validateScreenName(formats strfmt.Registry) error { 107 108 if err := validate.Required("screenName", "body", m.ScreenName); err != nil { 109 return err 110 } 111 112 if err := validate.MinLength("screenName", "body", *m.ScreenName, 3); err != nil { 113 return err 114 } 115 116 if err := validate.MaxLength("screenName", "body", *m.ScreenName, 255); err != nil { 117 return err 118 } 119 120 if err := validate.Pattern("screenName", "body", *m.ScreenName, `\w[\w_-]+`); err != nil { 121 return err 122 } 123 124 return nil 125 } 126 127 // ContextValidate validate this user card based on the context it is used 128 func (m *UserCard) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 129 var res []error 130 131 if err := m.contextValidateAdmin(ctx, formats); err != nil { 132 res = append(res, err) 133 } 134 135 if err := m.contextValidateAvailableKarma(ctx, formats); err != nil { 136 res = append(res, err) 137 } 138 139 if err := m.contextValidateID(ctx, formats); err != nil { 140 res = append(res, err) 141 } 142 143 if len(res) > 0 { 144 return errors.CompositeValidationError(res...) 145 } 146 return nil 147 } 148 149 func (m *UserCard) contextValidateAdmin(ctx context.Context, formats strfmt.Registry) error { 150 151 if err := validate.ReadOnly(ctx, "admin", "body", m.Admin); err != nil { 152 return err 153 } 154 155 return nil 156 } 157 158 func (m *UserCard) contextValidateAvailableKarma(ctx context.Context, formats strfmt.Registry) error { 159 160 if err := validate.ReadOnly(ctx, "availableKarma", "body", float64(m.AvailableKarma)); err != nil { 161 return err 162 } 163 164 return nil 165 } 166 167 func (m *UserCard) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 168 169 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 170 return err 171 } 172 173 return nil 174 } 175 176 // MarshalBinary interface implementation 177 func (m *UserCard) MarshalBinary() ([]byte, error) { 178 if m == nil { 179 return nil, nil 180 } 181 return swag.WriteJSON(m) 182 } 183 184 // UnmarshalBinary interface implementation 185 func (m *UserCard) UnmarshalBinary(b []byte) error { 186 var res UserCard 187 if err := swag.ReadJSON(b, &res); err != nil { 188 return err 189 } 190 *m = res 191 return nil 192 }