github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/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 "strconv" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Pet pet 19 // 20 // swagger:model Pet 21 type Pet struct { 22 23 // category 24 Category *Category `json:"category,omitempty"` 25 26 // id 27 ID int64 `json:"id,omitempty"` 28 29 // name 30 // Example: doggie 31 // Required: true 32 Name *string `json:"name"` 33 34 // photo urls 35 // Required: true 36 PhotoUrls []string `json:"photoUrls"` 37 38 // pet status in the store 39 Status string `json:"status,omitempty"` 40 41 // tags 42 Tags []*Tag `json:"tags"` 43 } 44 45 // Validate validates this pet 46 func (m *Pet) Validate(formats strfmt.Registry) error { 47 var res []error 48 49 if err := m.validateCategory(formats); err != nil { 50 res = append(res, err) 51 } 52 53 if err := m.validateName(formats); err != nil { 54 res = append(res, err) 55 } 56 57 if err := m.validatePhotoUrls(formats); err != nil { 58 res = append(res, err) 59 } 60 61 if err := m.validateTags(formats); err != nil { 62 res = append(res, err) 63 } 64 65 if len(res) > 0 { 66 return errors.CompositeValidationError(res...) 67 } 68 return nil 69 } 70 71 func (m *Pet) validateCategory(formats strfmt.Registry) error { 72 if swag.IsZero(m.Category) { // not required 73 return nil 74 } 75 76 if m.Category != nil { 77 if err := m.Category.Validate(formats); err != nil { 78 if ve, ok := err.(*errors.Validation); ok { 79 return ve.ValidateName("category") 80 } else if ce, ok := err.(*errors.CompositeError); ok { 81 return ce.ValidateName("category") 82 } 83 return err 84 } 85 } 86 87 return nil 88 } 89 90 func (m *Pet) validateName(formats strfmt.Registry) error { 91 92 if err := validate.Required("name", "body", m.Name); err != nil { 93 return err 94 } 95 96 return nil 97 } 98 99 func (m *Pet) validatePhotoUrls(formats strfmt.Registry) error { 100 101 if err := validate.Required("photoUrls", "body", m.PhotoUrls); err != nil { 102 return err 103 } 104 105 return nil 106 } 107 108 func (m *Pet) validateTags(formats strfmt.Registry) error { 109 if swag.IsZero(m.Tags) { // not required 110 return nil 111 } 112 113 for i := 0; i < len(m.Tags); i++ { 114 if swag.IsZero(m.Tags[i]) { // not required 115 continue 116 } 117 118 if m.Tags[i] != nil { 119 if err := m.Tags[i].Validate(formats); err != nil { 120 if ve, ok := err.(*errors.Validation); ok { 121 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 122 } else if ce, ok := err.(*errors.CompositeError); ok { 123 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 124 } 125 return err 126 } 127 } 128 129 } 130 131 return nil 132 } 133 134 // ContextValidate validate this pet based on the context it is used 135 func (m *Pet) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 136 var res []error 137 138 if err := m.contextValidateCategory(ctx, formats); err != nil { 139 res = append(res, err) 140 } 141 142 if err := m.contextValidateTags(ctx, formats); err != nil { 143 res = append(res, err) 144 } 145 146 if len(res) > 0 { 147 return errors.CompositeValidationError(res...) 148 } 149 return nil 150 } 151 152 func (m *Pet) contextValidateCategory(ctx context.Context, formats strfmt.Registry) error { 153 154 if m.Category != nil { 155 156 if swag.IsZero(m.Category) { // not required 157 return nil 158 } 159 160 if err := m.Category.ContextValidate(ctx, formats); err != nil { 161 if ve, ok := err.(*errors.Validation); ok { 162 return ve.ValidateName("category") 163 } else if ce, ok := err.(*errors.CompositeError); ok { 164 return ce.ValidateName("category") 165 } 166 return err 167 } 168 } 169 170 return nil 171 } 172 173 func (m *Pet) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 174 175 for i := 0; i < len(m.Tags); i++ { 176 177 if m.Tags[i] != nil { 178 179 if swag.IsZero(m.Tags[i]) { // not required 180 return nil 181 } 182 183 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 184 if ve, ok := err.(*errors.Validation); ok { 185 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 186 } else if ce, ok := err.(*errors.CompositeError); ok { 187 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 188 } 189 return err 190 } 191 } 192 193 } 194 195 return nil 196 } 197 198 // MarshalBinary interface implementation 199 func (m *Pet) MarshalBinary() ([]byte, error) { 200 if m == nil { 201 return nil, nil 202 } 203 return swag.WriteJSON(m) 204 } 205 206 // UnmarshalBinary interface implementation 207 func (m *Pet) UnmarshalBinary(b []byte) error { 208 var res Pet 209 if err := swag.ReadJSON(b, &res); err != nil { 210 return err 211 } 212 *m = res 213 return nil 214 }