github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/ingredient_option.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package inventory_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/go-openapi/validate" 16 ) 17 18 // IngredientOption Ingredient Option 19 // 20 // Parameters to the build of this ingredient that should be applied if the conditions are met. Must specify either command line args, resource requirements, or both. 21 // 22 // swagger:model ingredientOption 23 type IngredientOption struct { 24 25 // Command-line arguments to append to the builder invocation 26 // Min Items: 1 27 CommandLineArgs []string `json:"command_line_args"` 28 29 // At least one condition set from this list must be satisfied for this ingredient option to be applied in a recipe (i.e condition sets are ORed together) 30 ConditionSets []*IngredientOptionConditionSet `json:"condition_sets"` 31 32 // resources 33 Resources *IngredientOptionResources `json:"resources,omitempty"` 34 } 35 36 // Validate validates this ingredient option 37 func (m *IngredientOption) Validate(formats strfmt.Registry) error { 38 var res []error 39 40 if err := m.validateCommandLineArgs(formats); err != nil { 41 res = append(res, err) 42 } 43 44 if err := m.validateConditionSets(formats); err != nil { 45 res = append(res, err) 46 } 47 48 if err := m.validateResources(formats); err != nil { 49 res = append(res, err) 50 } 51 52 if len(res) > 0 { 53 return errors.CompositeValidationError(res...) 54 } 55 return nil 56 } 57 58 func (m *IngredientOption) validateCommandLineArgs(formats strfmt.Registry) error { 59 if swag.IsZero(m.CommandLineArgs) { // not required 60 return nil 61 } 62 63 iCommandLineArgsSize := int64(len(m.CommandLineArgs)) 64 65 if err := validate.MinItems("command_line_args", "body", iCommandLineArgsSize, 1); err != nil { 66 return err 67 } 68 69 for i := 0; i < len(m.CommandLineArgs); i++ { 70 71 if err := validate.MinLength("command_line_args"+"."+strconv.Itoa(i), "body", m.CommandLineArgs[i], 1); err != nil { 72 return err 73 } 74 75 } 76 77 return nil 78 } 79 80 func (m *IngredientOption) validateConditionSets(formats strfmt.Registry) error { 81 if swag.IsZero(m.ConditionSets) { // not required 82 return nil 83 } 84 85 for i := 0; i < len(m.ConditionSets); i++ { 86 if swag.IsZero(m.ConditionSets[i]) { // not required 87 continue 88 } 89 90 if m.ConditionSets[i] != nil { 91 if err := m.ConditionSets[i].Validate(formats); err != nil { 92 if ve, ok := err.(*errors.Validation); ok { 93 return ve.ValidateName("condition_sets" + "." + strconv.Itoa(i)) 94 } 95 return err 96 } 97 } 98 99 } 100 101 return nil 102 } 103 104 func (m *IngredientOption) validateResources(formats strfmt.Registry) error { 105 if swag.IsZero(m.Resources) { // not required 106 return nil 107 } 108 109 if m.Resources != nil { 110 if err := m.Resources.Validate(formats); err != nil { 111 if ve, ok := err.(*errors.Validation); ok { 112 return ve.ValidateName("resources") 113 } 114 return err 115 } 116 } 117 118 return nil 119 } 120 121 // ContextValidate validate this ingredient option based on the context it is used 122 func (m *IngredientOption) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 123 var res []error 124 125 if err := m.contextValidateConditionSets(ctx, formats); err != nil { 126 res = append(res, err) 127 } 128 129 if err := m.contextValidateResources(ctx, formats); err != nil { 130 res = append(res, err) 131 } 132 133 if len(res) > 0 { 134 return errors.CompositeValidationError(res...) 135 } 136 return nil 137 } 138 139 func (m *IngredientOption) contextValidateConditionSets(ctx context.Context, formats strfmt.Registry) error { 140 141 for i := 0; i < len(m.ConditionSets); i++ { 142 143 if m.ConditionSets[i] != nil { 144 if err := m.ConditionSets[i].ContextValidate(ctx, formats); err != nil { 145 if ve, ok := err.(*errors.Validation); ok { 146 return ve.ValidateName("condition_sets" + "." + strconv.Itoa(i)) 147 } 148 return err 149 } 150 } 151 152 } 153 154 return nil 155 } 156 157 func (m *IngredientOption) contextValidateResources(ctx context.Context, formats strfmt.Registry) error { 158 159 if m.Resources != nil { 160 if err := m.Resources.ContextValidate(ctx, formats); err != nil { 161 if ve, ok := err.(*errors.Validation); ok { 162 return ve.ValidateName("resources") 163 } 164 return err 165 } 166 } 167 168 return nil 169 } 170 171 // MarshalBinary interface implementation 172 func (m *IngredientOption) MarshalBinary() ([]byte, error) { 173 if m == nil { 174 return nil, nil 175 } 176 return swag.WriteJSON(m) 177 } 178 179 // UnmarshalBinary interface implementation 180 func (m *IngredientOption) UnmarshalBinary(b []byte) error { 181 var res IngredientOption 182 if err := swag.ReadJSON(b, &res); err != nil { 183 return err 184 } 185 *m = res 186 return nil 187 }