github.com/circl-dev/go-swagger@v0.31.0/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/circl-dev/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 if err := m.Category.ContextValidate(ctx, formats); err != nil { 156 if ve, ok := err.(*errors.Validation); ok { 157 return ve.ValidateName("category") 158 } else if ce, ok := err.(*errors.CompositeError); ok { 159 return ce.ValidateName("category") 160 } 161 return err 162 } 163 } 164 165 return nil 166 } 167 168 func (m *Pet) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { 169 170 for i := 0; i < len(m.Tags); i++ { 171 172 if m.Tags[i] != nil { 173 if err := m.Tags[i].ContextValidate(ctx, formats); err != nil { 174 if ve, ok := err.(*errors.Validation); ok { 175 return ve.ValidateName("tags" + "." + strconv.Itoa(i)) 176 } else if ce, ok := err.(*errors.CompositeError); ok { 177 return ce.ValidateName("tags" + "." + strconv.Itoa(i)) 178 } 179 return err 180 } 181 } 182 183 } 184 185 return nil 186 } 187 188 // MarshalBinary interface implementation 189 func (m *Pet) MarshalBinary() ([]byte, error) { 190 if m == nil { 191 return nil, nil 192 } 193 return swag.WriteJSON(m) 194 } 195 196 // UnmarshalBinary interface implementation 197 func (m *Pet) UnmarshalBinary(b []byte) error { 198 var res Pet 199 if err := swag.ReadJSON(b, &res); err != nil { 200 return err 201 } 202 *m = res 203 return nil 204 }