github.com/circl-dev/go-swagger@v0.31.0/examples/composed-auth/models/order.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 // Order order 19 // 20 // swagger:model Order 21 type Order struct { 22 23 // order ID 24 // Required: true 25 OrderID *string `json:"orderID"` 26 27 // order lines 28 OrderLines []*OrderLine `json:"orderLines"` 29 } 30 31 // Validate validates this order 32 func (m *Order) Validate(formats strfmt.Registry) error { 33 var res []error 34 35 if err := m.validateOrderID(formats); err != nil { 36 res = append(res, err) 37 } 38 39 if err := m.validateOrderLines(formats); err != nil { 40 res = append(res, err) 41 } 42 43 if len(res) > 0 { 44 return errors.CompositeValidationError(res...) 45 } 46 return nil 47 } 48 49 func (m *Order) validateOrderID(formats strfmt.Registry) error { 50 51 if err := validate.Required("orderID", "body", m.OrderID); err != nil { 52 return err 53 } 54 55 return nil 56 } 57 58 func (m *Order) validateOrderLines(formats strfmt.Registry) error { 59 if swag.IsZero(m.OrderLines) { // not required 60 return nil 61 } 62 63 for i := 0; i < len(m.OrderLines); i++ { 64 if swag.IsZero(m.OrderLines[i]) { // not required 65 continue 66 } 67 68 if m.OrderLines[i] != nil { 69 if err := m.OrderLines[i].Validate(formats); err != nil { 70 if ve, ok := err.(*errors.Validation); ok { 71 return ve.ValidateName("orderLines" + "." + strconv.Itoa(i)) 72 } else if ce, ok := err.(*errors.CompositeError); ok { 73 return ce.ValidateName("orderLines" + "." + strconv.Itoa(i)) 74 } 75 return err 76 } 77 } 78 79 } 80 81 return nil 82 } 83 84 // ContextValidate validate this order based on the context it is used 85 func (m *Order) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 86 var res []error 87 88 if err := m.contextValidateOrderLines(ctx, formats); err != nil { 89 res = append(res, err) 90 } 91 92 if len(res) > 0 { 93 return errors.CompositeValidationError(res...) 94 } 95 return nil 96 } 97 98 func (m *Order) contextValidateOrderLines(ctx context.Context, formats strfmt.Registry) error { 99 100 for i := 0; i < len(m.OrderLines); i++ { 101 102 if m.OrderLines[i] != nil { 103 if err := m.OrderLines[i].ContextValidate(ctx, formats); err != nil { 104 if ve, ok := err.(*errors.Validation); ok { 105 return ve.ValidateName("orderLines" + "." + strconv.Itoa(i)) 106 } else if ce, ok := err.(*errors.CompositeError); ok { 107 return ce.ValidateName("orderLines" + "." + strconv.Itoa(i)) 108 } 109 return err 110 } 111 } 112 113 } 114 115 return nil 116 } 117 118 // MarshalBinary interface implementation 119 func (m *Order) MarshalBinary() ([]byte, error) { 120 if m == nil { 121 return nil, nil 122 } 123 return swag.WriteJSON(m) 124 } 125 126 // UnmarshalBinary interface implementation 127 func (m *Order) UnmarshalBinary(b []byte) error { 128 var res Order 129 if err := swag.ReadJSON(b, &res); err != nil { 130 return err 131 } 132 *m = res 133 return nil 134 } 135 136 // OrderLine order line 137 // 138 // swagger:model orderLine 139 type OrderLine struct { 140 141 // purchased item 142 // Required: true 143 PurchasedItem *Item `json:"purchasedItem"` 144 145 // quantity 146 // Required: true 147 // Minimum: 1 148 Quantity *int32 `json:"quantity"` 149 } 150 151 // Validate validates this order line 152 func (m *OrderLine) Validate(formats strfmt.Registry) error { 153 var res []error 154 155 if err := m.validatePurchasedItem(formats); err != nil { 156 res = append(res, err) 157 } 158 159 if err := m.validateQuantity(formats); err != nil { 160 res = append(res, err) 161 } 162 163 if len(res) > 0 { 164 return errors.CompositeValidationError(res...) 165 } 166 return nil 167 } 168 169 func (m *OrderLine) validatePurchasedItem(formats strfmt.Registry) error { 170 171 if err := validate.Required("purchasedItem", "body", m.PurchasedItem); err != nil { 172 return err 173 } 174 175 if err := validate.Required("purchasedItem", "body", m.PurchasedItem); err != nil { 176 return err 177 } 178 179 if m.PurchasedItem != nil { 180 if err := m.PurchasedItem.Validate(formats); err != nil { 181 if ve, ok := err.(*errors.Validation); ok { 182 return ve.ValidateName("purchasedItem") 183 } else if ce, ok := err.(*errors.CompositeError); ok { 184 return ce.ValidateName("purchasedItem") 185 } 186 return err 187 } 188 } 189 190 return nil 191 } 192 193 func (m *OrderLine) validateQuantity(formats strfmt.Registry) error { 194 195 if err := validate.Required("quantity", "body", m.Quantity); err != nil { 196 return err 197 } 198 199 if err := validate.MinimumInt("quantity", "body", int64(*m.Quantity), 1, false); err != nil { 200 return err 201 } 202 203 return nil 204 } 205 206 // ContextValidate validate this order line based on the context it is used 207 func (m *OrderLine) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 208 var res []error 209 210 if err := m.contextValidatePurchasedItem(ctx, formats); err != nil { 211 res = append(res, err) 212 } 213 214 if len(res) > 0 { 215 return errors.CompositeValidationError(res...) 216 } 217 return nil 218 } 219 220 func (m *OrderLine) contextValidatePurchasedItem(ctx context.Context, formats strfmt.Registry) error { 221 222 if m.PurchasedItem != nil { 223 if err := m.PurchasedItem.ContextValidate(ctx, formats); err != nil { 224 if ve, ok := err.(*errors.Validation); ok { 225 return ve.ValidateName("purchasedItem") 226 } else if ce, ok := err.(*errors.CompositeError); ok { 227 return ce.ValidateName("purchasedItem") 228 } 229 return err 230 } 231 } 232 233 return nil 234 } 235 236 // MarshalBinary interface implementation 237 func (m *OrderLine) MarshalBinary() ([]byte, error) { 238 if m == nil { 239 return nil, nil 240 } 241 return swag.WriteJSON(m) 242 } 243 244 // UnmarshalBinary interface implementation 245 func (m *OrderLine) UnmarshalBinary(b []byte) error { 246 var res OrderLine 247 if err := swag.ReadJSON(b, &res); err != nil { 248 return err 249 } 250 *m = res 251 return nil 252 }