291 lines
6.3 KiB
Go
291 lines
6.3 KiB
Go
// Code generated by go-swagger; DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
// This file was generated by the swagger tool.
|
|
// Editing this file might prove futile when you re-run the swagger generate command
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"github.com/go-openapi/errors"
|
|
"github.com/go-openapi/strfmt"
|
|
"github.com/go-openapi/swag"
|
|
"github.com/go-openapi/validate"
|
|
)
|
|
|
|
// CustomerCollection customer collection
|
|
//
|
|
// swagger:model CustomerCollection
|
|
type CustomerCollection struct {
|
|
|
|
// billable
|
|
// Required: true
|
|
Billable *bool `json:"billable"`
|
|
|
|
// The assigned color in HTML hex format, eg. #dd1d00
|
|
Color string `json:"color,omitempty"`
|
|
|
|
// comment
|
|
Comment string `json:"comment,omitempty"`
|
|
|
|
// currency
|
|
// Required: true
|
|
// Max Length: 3
|
|
Currency *string `json:"currency"`
|
|
|
|
// id
|
|
ID int64 `json:"id,omitempty"`
|
|
|
|
// Meta fields
|
|
//
|
|
// All visible meta (custom) fields registered with this customer
|
|
MetaFields []*CustomerMeta `json:"metaFields"`
|
|
|
|
// name
|
|
// Required: true
|
|
// Max Length: 150
|
|
// Min Length: 2
|
|
Name *string `json:"name"`
|
|
|
|
// number
|
|
// Max Length: 50
|
|
Number string `json:"number,omitempty"`
|
|
|
|
// Teams
|
|
//
|
|
// If no team is assigned, everyone can access the customer
|
|
Teams []*Team `json:"teams"`
|
|
|
|
// visible
|
|
// Required: true
|
|
Visible *bool `json:"visible"`
|
|
}
|
|
|
|
// Validate validates this customer collection
|
|
func (m *CustomerCollection) Validate(formats strfmt.Registry) error {
|
|
var res []error
|
|
|
|
if err := m.validateBillable(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateCurrency(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateMetaFields(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateName(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateNumber(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateTeams(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateVisible(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if len(res) > 0 {
|
|
return errors.CompositeValidationError(res...)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateBillable(formats strfmt.Registry) error {
|
|
|
|
if err := validate.Required("billable", "body", m.Billable); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateCurrency(formats strfmt.Registry) error {
|
|
|
|
if err := validate.Required("currency", "body", m.Currency); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := validate.MaxLength("currency", "body", *m.Currency, 3); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateMetaFields(formats strfmt.Registry) error {
|
|
if swag.IsZero(m.MetaFields) { // not required
|
|
return nil
|
|
}
|
|
|
|
for i := 0; i < len(m.MetaFields); i++ {
|
|
if swag.IsZero(m.MetaFields[i]) { // not required
|
|
continue
|
|
}
|
|
|
|
if m.MetaFields[i] != nil {
|
|
if err := m.MetaFields[i].Validate(formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("metaFields" + "." + strconv.Itoa(i))
|
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
|
return ce.ValidateName("metaFields" + "." + strconv.Itoa(i))
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateName(formats strfmt.Registry) error {
|
|
|
|
if err := validate.Required("name", "body", m.Name); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := validate.MinLength("name", "body", *m.Name, 2); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := validate.MaxLength("name", "body", *m.Name, 150); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateNumber(formats strfmt.Registry) error {
|
|
if swag.IsZero(m.Number) { // not required
|
|
return nil
|
|
}
|
|
|
|
if err := validate.MaxLength("number", "body", m.Number, 50); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateTeams(formats strfmt.Registry) error {
|
|
if swag.IsZero(m.Teams) { // not required
|
|
return nil
|
|
}
|
|
|
|
for i := 0; i < len(m.Teams); i++ {
|
|
if swag.IsZero(m.Teams[i]) { // not required
|
|
continue
|
|
}
|
|
|
|
if m.Teams[i] != nil {
|
|
if err := m.Teams[i].Validate(formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("teams" + "." + strconv.Itoa(i))
|
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
|
return ce.ValidateName("teams" + "." + strconv.Itoa(i))
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) validateVisible(formats strfmt.Registry) error {
|
|
|
|
if err := validate.Required("visible", "body", m.Visible); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ContextValidate validate this customer collection based on the context it is used
|
|
func (m *CustomerCollection) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
|
var res []error
|
|
|
|
if err := m.contextValidateMetaFields(ctx, formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.contextValidateTeams(ctx, formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if len(res) > 0 {
|
|
return errors.CompositeValidationError(res...)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) contextValidateMetaFields(ctx context.Context, formats strfmt.Registry) error {
|
|
|
|
for i := 0; i < len(m.MetaFields); i++ {
|
|
|
|
if m.MetaFields[i] != nil {
|
|
if err := m.MetaFields[i].ContextValidate(ctx, formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("metaFields" + "." + strconv.Itoa(i))
|
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
|
return ce.ValidateName("metaFields" + "." + strconv.Itoa(i))
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *CustomerCollection) contextValidateTeams(ctx context.Context, formats strfmt.Registry) error {
|
|
|
|
for i := 0; i < len(m.Teams); i++ {
|
|
|
|
if m.Teams[i] != nil {
|
|
if err := m.Teams[i].ContextValidate(ctx, formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("teams" + "." + strconv.Itoa(i))
|
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
|
return ce.ValidateName("teams" + "." + strconv.Itoa(i))
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MarshalBinary interface implementation
|
|
func (m *CustomerCollection) MarshalBinary() ([]byte, error) {
|
|
if m == nil {
|
|
return nil, nil
|
|
}
|
|
return swag.WriteJSON(m)
|
|
}
|
|
|
|
// UnmarshalBinary interface implementation
|
|
func (m *CustomerCollection) UnmarshalBinary(b []byte) error {
|
|
var res CustomerCollection
|
|
if err := swag.ReadJSON(b, &res); err != nil {
|
|
return err
|
|
}
|
|
*m = res
|
|
return nil
|
|
}
|