github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_package_item.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 ) 16 17 // Billing20201105PackageItem PackageItem defines a specific billable component of a Package. 18 // 19 // swagger:model billing_20201105PackageItem 20 type Billing20201105PackageItem struct { 21 22 // key is the identifier for this particular item. 23 Key string `json:"key,omitempty"` 24 25 // optional represents if a selection 26 Optional bool `json:"optional,omitempty"` 27 28 // options represents a list of options a user can select when signing up for this package. 29 Options []*Billing20201105PackageOption `json:"options"` 30 31 // type defines what kind of type this item is. 32 Type *Billing20201105PackageItemType `json:"type,omitempty"` 33 } 34 35 // Validate validates this billing 20201105 package item 36 func (m *Billing20201105PackageItem) Validate(formats strfmt.Registry) error { 37 var res []error 38 39 if err := m.validateOptions(formats); err != nil { 40 res = append(res, err) 41 } 42 43 if err := m.validateType(formats); err != nil { 44 res = append(res, err) 45 } 46 47 if len(res) > 0 { 48 return errors.CompositeValidationError(res...) 49 } 50 return nil 51 } 52 53 func (m *Billing20201105PackageItem) validateOptions(formats strfmt.Registry) error { 54 if swag.IsZero(m.Options) { // not required 55 return nil 56 } 57 58 for i := 0; i < len(m.Options); i++ { 59 if swag.IsZero(m.Options[i]) { // not required 60 continue 61 } 62 63 if m.Options[i] != nil { 64 if err := m.Options[i].Validate(formats); err != nil { 65 if ve, ok := err.(*errors.Validation); ok { 66 return ve.ValidateName("options" + "." + strconv.Itoa(i)) 67 } else if ce, ok := err.(*errors.CompositeError); ok { 68 return ce.ValidateName("options" + "." + strconv.Itoa(i)) 69 } 70 return err 71 } 72 } 73 74 } 75 76 return nil 77 } 78 79 func (m *Billing20201105PackageItem) validateType(formats strfmt.Registry) error { 80 if swag.IsZero(m.Type) { // not required 81 return nil 82 } 83 84 if m.Type != nil { 85 if err := m.Type.Validate(formats); err != nil { 86 if ve, ok := err.(*errors.Validation); ok { 87 return ve.ValidateName("type") 88 } else if ce, ok := err.(*errors.CompositeError); ok { 89 return ce.ValidateName("type") 90 } 91 return err 92 } 93 } 94 95 return nil 96 } 97 98 // ContextValidate validate this billing 20201105 package item based on the context it is used 99 func (m *Billing20201105PackageItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 100 var res []error 101 102 if err := m.contextValidateOptions(ctx, formats); err != nil { 103 res = append(res, err) 104 } 105 106 if err := m.contextValidateType(ctx, formats); err != nil { 107 res = append(res, err) 108 } 109 110 if len(res) > 0 { 111 return errors.CompositeValidationError(res...) 112 } 113 return nil 114 } 115 116 func (m *Billing20201105PackageItem) contextValidateOptions(ctx context.Context, formats strfmt.Registry) error { 117 118 for i := 0; i < len(m.Options); i++ { 119 120 if m.Options[i] != nil { 121 if err := m.Options[i].ContextValidate(ctx, formats); err != nil { 122 if ve, ok := err.(*errors.Validation); ok { 123 return ve.ValidateName("options" + "." + strconv.Itoa(i)) 124 } else if ce, ok := err.(*errors.CompositeError); ok { 125 return ce.ValidateName("options" + "." + strconv.Itoa(i)) 126 } 127 return err 128 } 129 } 130 131 } 132 133 return nil 134 } 135 136 func (m *Billing20201105PackageItem) contextValidateType(ctx context.Context, formats strfmt.Registry) error { 137 138 if m.Type != nil { 139 if err := m.Type.ContextValidate(ctx, formats); err != nil { 140 if ve, ok := err.(*errors.Validation); ok { 141 return ve.ValidateName("type") 142 } else if ce, ok := err.(*errors.CompositeError); ok { 143 return ce.ValidateName("type") 144 } 145 return err 146 } 147 } 148 149 return nil 150 } 151 152 // MarshalBinary interface implementation 153 func (m *Billing20201105PackageItem) MarshalBinary() ([]byte, error) { 154 if m == nil { 155 return nil, nil 156 } 157 return swag.WriteJSON(m) 158 } 159 160 // UnmarshalBinary interface implementation 161 func (m *Billing20201105PackageItem) UnmarshalBinary(b []byte) error { 162 var res Billing20201105PackageItem 163 if err := swag.ReadJSON(b, &res); err != nil { 164 return err 165 } 166 *m = res 167 return nil 168 }