github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/contributed-templates/stratoscale/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 "encoding/json" 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 // Order order 19 // 20 // swagger:model Order 21 type Order struct { 22 23 // complete 24 Complete *bool `json:"complete,omitempty"` 25 26 // id 27 ID int64 `json:"id,omitempty"` 28 29 // pet Id 30 PetID int64 `json:"petId,omitempty"` 31 32 // quantity 33 Quantity int32 `json:"quantity,omitempty"` 34 35 // ship date 36 // Format: date-time 37 ShipDate strfmt.DateTime `json:"shipDate,omitempty"` 38 39 // Order Status 40 // Enum: ["placed","approved","delivered"] 41 Status string `json:"status,omitempty"` 42 } 43 44 // Validate validates this order 45 func (m *Order) Validate(formats strfmt.Registry) error { 46 var res []error 47 48 if err := m.validateShipDate(formats); err != nil { 49 res = append(res, err) 50 } 51 52 if err := m.validateStatus(formats); err != nil { 53 res = append(res, err) 54 } 55 56 if len(res) > 0 { 57 return errors.CompositeValidationError(res...) 58 } 59 return nil 60 } 61 62 func (m *Order) validateShipDate(formats strfmt.Registry) error { 63 if swag.IsZero(m.ShipDate) { // not required 64 return nil 65 } 66 67 if err := validate.FormatOf("shipDate", "body", "date-time", m.ShipDate.String(), formats); err != nil { 68 return err 69 } 70 71 return nil 72 } 73 74 var orderTypeStatusPropEnum []interface{} 75 76 func init() { 77 var res []string 78 if err := json.Unmarshal([]byte(`["placed","approved","delivered"]`), &res); err != nil { 79 panic(err) 80 } 81 for _, v := range res { 82 orderTypeStatusPropEnum = append(orderTypeStatusPropEnum, v) 83 } 84 } 85 86 const ( 87 88 // OrderStatusPlaced captures enum value "placed" 89 OrderStatusPlaced string = "placed" 90 91 // OrderStatusApproved captures enum value "approved" 92 OrderStatusApproved string = "approved" 93 94 // OrderStatusDelivered captures enum value "delivered" 95 OrderStatusDelivered string = "delivered" 96 ) 97 98 // prop value enum 99 func (m *Order) validateStatusEnum(path, location string, value string) error { 100 if err := validate.EnumCase(path, location, value, orderTypeStatusPropEnum, true); err != nil { 101 return err 102 } 103 return nil 104 } 105 106 func (m *Order) validateStatus(formats strfmt.Registry) error { 107 if swag.IsZero(m.Status) { // not required 108 return nil 109 } 110 111 // value enum 112 if err := m.validateStatusEnum("status", "body", m.Status); err != nil { 113 return err 114 } 115 116 return nil 117 } 118 119 // ContextValidate validates this order based on context it is used 120 func (m *Order) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 121 return nil 122 } 123 124 // MarshalBinary interface implementation 125 func (m *Order) MarshalBinary() ([]byte, error) { 126 if m == nil { 127 return nil, nil 128 } 129 return swag.WriteJSON(m) 130 } 131 132 // UnmarshalBinary interface implementation 133 func (m *Order) UnmarshalBinary(b []byte) error { 134 var res Order 135 if err := swag.ReadJSON(b, &res); err != nil { 136 return err 137 } 138 *m = res 139 return nil 140 }