github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/contributed-templates/stratoscale/models/pet.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/go-openapi/validate" 17 ) 18 19 // Pet pet 20 // 21 // swagger:model Pet 22 type Pet struct { 23 24 // category 25 Category *Category `json:"category,omitempty"` 26 27 // id 28 ID int64 `json:"id,omitempty" gorm:"primary_key" query:"filter,sort"` 29 30 // name 31 // Example: doggie 32 // Required: true 33 Name *string `json:"name" query:"filter,sort"` 34 35 // photo urls 36 // Required: true 37 PhotoUrls []string `json:"photoUrls" gorm:"-"` 38 39 // pet status in the store 40 // Enum: ["available","pending","sold"] 41 Status string `json:"status,omitempty" query:"filter,sort"` 42 43 // tags 44 Tags []*Tag `json:"tags"` 45 } 46 47 // Validate validates this pet 48 func (m *Pet) Validate(formats strfmt.Registry) error { 49 var res []error 50 51 if err := m.validateCategory(formats); err != nil { 52 res = append(res, err) 53 } 54 55 if err := m.validateName(formats); err != nil { 56 res = append(res, err) 57 } 58 59 if err := m.validatePhotoUrls(formats); err != nil { 60 res = append(res, err) 61 } 62 63 if err := m.validateStatus(formats); err != nil { 64 res = append(res, err) 65 } 66 67 if err := m.validateTags(formats); err != nil { 68 res = append(res, err) 69 } 70 71 if len(res) > 0 { 72 return errors.CompositeValidationError(res...) 73 } 74 return nil 75 } 76 77 func (m *Pet) validateCategory(formats strfmt.Registry) error { 78 if swag.IsZero(m.Category) { // not required 79 return nil 80 } 81 82 if m.Category != nil { 83 if err := m.Category.Validate(formats); err != nil { 84 if ve, ok := err.(*errors.Validation); ok { 85 return ve.ValidateName("category") 86 } else if ce, ok := err.(*errors.CompositeError); ok { 87 return ce.ValidateName("category") 88 } 89 return err 90 } 91 } 92 93 return nil 94 } 95 96 func (m *Pet) validateName(formats strfmt.Registry) error { 97 98 if err := validate.Required("name", "body", m.Name); err != nil { 99 return err 100 } 101 102 return nil 103 } 104 105 func (m *Pet) validatePhotoUrls(formats strfmt.Registry) error { 106 107 if err := validate.Required("photoUrls", "body", m.PhotoUrls); err != nil { 108 return err 109 } 110 111 return nil 112 } 113 114 var petTypeStatusPropEnum []interface{} 115 116 func init() { 117 var res []string 118 if err := json.Unmarshal([]byte(`["available","pending","sold"]`), &res); err != nil { 119 panic(err) 120 } 121 for _, v := range res { 122 petTypeStatusPropEnum = append(petTypeStatusPropEnum, v) 123 } 124 } 125 126 const ( 127 128 // PetStatusAvailable captures enum value "available" 129 PetStatusAvailable string = "available" 130 131 // PetStatusPending captures enum value "pending" 132 PetStatusPending string = "pending" 133 134 // PetStatusSold captures enum value "sold" 135 PetStatusSold string = "sold" 136 ) 137 138 // prop value enum 139 func (m *Pet) validateStatusEnum(path, location string, value string) error { 140 if err := validate.EnumCase(path, location, value, petTypeStatusPropEnum, true); err != nil { 141 return err 142 } 143 return nil 144 } 145 146 func (m *Pet) validateStatus(formats strfmt.Registry) error { 147 if swag.IsZero(m.Status) { // not required 148 return nil 149 } 150 151 // value enum 152 if err := m.validateStatusEnum("status", "body", m.Status); err != nil { 153 return err 154 } 155 156 return nil 157 } 158 159 func (m *Pet) validateTags(formats strfmt.Registry) error { 160 if swag.IsZero(m.Tags) { // not required 161 return nil 162 } 163 164 for i := 0; i < len(m.Tags); i++ { 165 if swag.IsZero(m.Tags[i]) { // not required 166 continue 167 } 168 169 if m.Tags[i] != nil { 170 if err := m.Tags[i].Validate(formats); err != nil { 171 if ve, ok := err.(*errors.Validation); ok { 172 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 173 } else if ce, ok := err.(*errors.CompositeError); ok { 174 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 175 } 176 return err 177 } 178 } 179 180 } 181 182 return nil 183 } 184 185 // ContextValidate validate this pet based on the context it is used 186 func (m *Pet) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 187 var res []error 188 189 if err := m.contextValidateCategory(ctx, formats); err != nil { 190 res = append(res, err) 191 } 192 193 if err := m.contextValidateTags(ctx, formats); err != nil { 194 res = append(res, err) 195 } 196 197 if len(res) > 0 { 198 return errors.CompositeValidationError(res...) 199 } 200 return nil 201 } 202 203 func (m *Pet) contextValidateCategory(ctx context.Context, formats strfmt.Registry) error { 204 205 if m.Category != nil { 206 207 if swag.IsZero(m.Category) { // not required 208 return nil 209 } 210 211 if err := m.Category.ContextValidate(ctx, formats); err != nil { 212 if ve, ok := err.(*errors.Validation); ok { 213 return ve.ValidateName("category") 214 } else if ce, ok := err.(*errors.CompositeError); ok { 215 return ce.ValidateName("category") 216 } 217 return err 218 } 219 } 220 221 return nil 222 } 223 224 func (m *Pet) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 225 226 for i := 0; i < len(m.Tags); i++ { 227 228 if m.Tags[i] != nil { 229 230 if swag.IsZero(m.Tags[i]) { // not required 231 return nil 232 } 233 234 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 235 if ve, ok := err.(*errors.Validation); ok { 236 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 237 } else if ce, ok := err.(*errors.CompositeError); ok { 238 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 239 } 240 return err 241 } 242 } 243 244 } 245 246 return nil 247 } 248 249 // MarshalBinary interface implementation 250 func (m *Pet) MarshalBinary() ([]byte, error) { 251 if m == nil { 252 return nil, nil 253 } 254 return swag.WriteJSON(m) 255 } 256 257 // UnmarshalBinary interface implementation 258 func (m *Pet) UnmarshalBinary(b []byte) error { 259 var res Pet 260 if err := swag.ReadJSON(b, &res); err != nil { 261 return err 262 } 263 *m = res 264 return nil 265 }