github.com/djarvur/go-swagger@v0.18.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  	"strconv"
    10  
    11  	strfmt "github.com/go-openapi/strfmt"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/go-openapi/validate"
    16  )
    17  
    18  // Order order
    19  // swagger:model Order
    20  type Order struct {
    21  
    22  	// order ID
    23  	// Required: true
    24  	OrderID *string `json:"orderID"`
    25  
    26  	// order lines
    27  	OrderLines []*OrderLine `json:"orderLines"`
    28  }
    29  
    30  // Validate validates this order
    31  func (m *Order) Validate(formats strfmt.Registry) error {
    32  	var res []error
    33  
    34  	if err := m.validateOrderID(formats); err != nil {
    35  		res = append(res, err)
    36  	}
    37  
    38  	if err := m.validateOrderLines(formats); err != nil {
    39  		res = append(res, err)
    40  	}
    41  
    42  	if len(res) > 0 {
    43  		return errors.CompositeValidationError(res...)
    44  	}
    45  	return nil
    46  }
    47  
    48  func (m *Order) validateOrderID(formats strfmt.Registry) error {
    49  
    50  	if err := validate.Required("orderID", "body", m.OrderID); err != nil {
    51  		return err
    52  	}
    53  
    54  	return nil
    55  }
    56  
    57  func (m *Order) validateOrderLines(formats strfmt.Registry) error {
    58  
    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  				}
    73  				return err
    74  			}
    75  		}
    76  
    77  	}
    78  
    79  	return nil
    80  }
    81  
    82  // MarshalBinary interface implementation
    83  func (m *Order) MarshalBinary() ([]byte, error) {
    84  	if m == nil {
    85  		return nil, nil
    86  	}
    87  	return swag.WriteJSON(m)
    88  }
    89  
    90  // UnmarshalBinary interface implementation
    91  func (m *Order) UnmarshalBinary(b []byte) error {
    92  	var res Order
    93  	if err := swag.ReadJSON(b, &res); err != nil {
    94  		return err
    95  	}
    96  	*m = res
    97  	return nil
    98  }
    99  
   100  // OrderLine order line
   101  // swagger:model orderLine
   102  type OrderLine struct {
   103  
   104  	// purchased item
   105  	// Required: true
   106  	PurchasedItem Item `json:"purchasedItem"`
   107  
   108  	// quantity
   109  	// Required: true
   110  	// Minimum: 1
   111  	Quantity *int32 `json:"quantity"`
   112  }
   113  
   114  // Validate validates this order line
   115  func (m *OrderLine) Validate(formats strfmt.Registry) error {
   116  	var res []error
   117  
   118  	if err := m.validatePurchasedItem(formats); err != nil {
   119  		res = append(res, err)
   120  	}
   121  
   122  	if err := m.validateQuantity(formats); err != nil {
   123  		res = append(res, err)
   124  	}
   125  
   126  	if len(res) > 0 {
   127  		return errors.CompositeValidationError(res...)
   128  	}
   129  	return nil
   130  }
   131  
   132  func (m *OrderLine) validatePurchasedItem(formats strfmt.Registry) error {
   133  
   134  	if err := m.PurchasedItem.Validate(formats); err != nil {
   135  		if ve, ok := err.(*errors.Validation); ok {
   136  			return ve.ValidateName("purchasedItem")
   137  		}
   138  		return err
   139  	}
   140  
   141  	return nil
   142  }
   143  
   144  func (m *OrderLine) validateQuantity(formats strfmt.Registry) error {
   145  
   146  	if err := validate.Required("quantity", "body", m.Quantity); err != nil {
   147  		return err
   148  	}
   149  
   150  	if err := validate.MinimumInt("quantity", "body", int64(*m.Quantity), 1, false); err != nil {
   151  		return err
   152  	}
   153  
   154  	return nil
   155  }
   156  
   157  // MarshalBinary interface implementation
   158  func (m *OrderLine) MarshalBinary() ([]byte, error) {
   159  	if m == nil {
   160  		return nil, nil
   161  	}
   162  	return swag.WriteJSON(m)
   163  }
   164  
   165  // UnmarshalBinary interface implementation
   166  func (m *OrderLine) UnmarshalBinary(b []byte) error {
   167  	var res OrderLine
   168  	if err := swag.ReadJSON(b, &res); err != nil {
   169  		return err
   170  	}
   171  	*m = res
   172  	return nil
   173  }