github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/recipe.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 // Recipe Recipe 19 // 20 // A recipe contains all required information (ingredient versions, platform, build options, etc.) to build a project for a single platform. 21 // 22 // swagger:model recipe 23 type Recipe struct { 24 25 // Camel-specific flags for controlling the build. 26 CamelFlags []string `json:"camel_flags"` 27 28 // Indicates whether this recipe came from the recipe store or not 29 // Required: true 30 FromRecipeStore *bool `json:"from_recipe_store"` 31 32 // image 33 // Required: true 34 Image *Image `json:"image"` 35 36 // If all of the resolved ingredients resolved to indemnified versions, then this will be true. 37 IsIndemnified *bool `json:"is_indemnified,omitempty"` 38 39 // platform 40 // Required: true 41 Platform *Platform `json:"platform"` 42 43 // This recipe's ID. Identical recipes will have the same ID. 44 // Required: true 45 // Format: uuid 46 RecipeID *strfmt.UUID `json:"recipe_id"` 47 48 // If the recipe came from the recipe store, this will contain the recipe's timestamp. Otherwise this field will be omitted 49 // Format: date-time 50 RecipeStoreTimestamp *strfmt.DateTime `json:"recipe_store_timestamp,omitempty"` 51 52 // The resolved ingredients that comprise this recipe. 53 // Required: true 54 // Min Items: 1 55 // Unique: true 56 ResolvedIngredients []*ResolvedIngredient `json:"resolved_ingredients"` 57 58 // The version of the solver that was used to create this recipe 59 // Required: true 60 SolverVersion *int64 `json:"solver_version"` 61 } 62 63 // Validate validates this recipe 64 func (m *Recipe) Validate(formats strfmt.Registry) error { 65 var res []error 66 67 if err := m.validateFromRecipeStore(formats); err != nil { 68 res = append(res, err) 69 } 70 71 if err := m.validateImage(formats); err != nil { 72 res = append(res, err) 73 } 74 75 if err := m.validatePlatform(formats); err != nil { 76 res = append(res, err) 77 } 78 79 if err := m.validateRecipeID(formats); err != nil { 80 res = append(res, err) 81 } 82 83 if err := m.validateRecipeStoreTimestamp(formats); err != nil { 84 res = append(res, err) 85 } 86 87 if err := m.validateResolvedIngredients(formats); err != nil { 88 res = append(res, err) 89 } 90 91 if err := m.validateSolverVersion(formats); err != nil { 92 res = append(res, err) 93 } 94 95 if len(res) > 0 { 96 return errors.CompositeValidationError(res...) 97 } 98 return nil 99 } 100 101 func (m *Recipe) validateFromRecipeStore(formats strfmt.Registry) error { 102 103 if err := validate.Required("from_recipe_store", "body", m.FromRecipeStore); err != nil { 104 return err 105 } 106 107 return nil 108 } 109 110 func (m *Recipe) validateImage(formats strfmt.Registry) error { 111 112 if err := validate.Required("image", "body", m.Image); err != nil { 113 return err 114 } 115 116 if m.Image != nil { 117 if err := m.Image.Validate(formats); err != nil { 118 if ve, ok := err.(*errors.Validation); ok { 119 return ve.ValidateName("image") 120 } 121 return err 122 } 123 } 124 125 return nil 126 } 127 128 func (m *Recipe) validatePlatform(formats strfmt.Registry) error { 129 130 if err := validate.Required("platform", "body", m.Platform); err != nil { 131 return err 132 } 133 134 if m.Platform != nil { 135 if err := m.Platform.Validate(formats); err != nil { 136 if ve, ok := err.(*errors.Validation); ok { 137 return ve.ValidateName("platform") 138 } 139 return err 140 } 141 } 142 143 return nil 144 } 145 146 func (m *Recipe) validateRecipeID(formats strfmt.Registry) error { 147 148 if err := validate.Required("recipe_id", "body", m.RecipeID); err != nil { 149 return err 150 } 151 152 if err := validate.FormatOf("recipe_id", "body", "uuid", m.RecipeID.String(), formats); err != nil { 153 return err 154 } 155 156 return nil 157 } 158 159 func (m *Recipe) validateRecipeStoreTimestamp(formats strfmt.Registry) error { 160 if swag.IsZero(m.RecipeStoreTimestamp) { // not required 161 return nil 162 } 163 164 if err := validate.FormatOf("recipe_store_timestamp", "body", "date-time", m.RecipeStoreTimestamp.String(), formats); err != nil { 165 return err 166 } 167 168 return nil 169 } 170 171 func (m *Recipe) validateResolvedIngredients(formats strfmt.Registry) error { 172 173 if err := validate.Required("resolved_ingredients", "body", m.ResolvedIngredients); err != nil { 174 return err 175 } 176 177 iResolvedIngredientsSize := int64(len(m.ResolvedIngredients)) 178 179 if err := validate.MinItems("resolved_ingredients", "body", iResolvedIngredientsSize, 1); err != nil { 180 return err 181 } 182 183 if err := validate.UniqueItems("resolved_ingredients", "body", m.ResolvedIngredients); err != nil { 184 return err 185 } 186 187 for i := 0; i < len(m.ResolvedIngredients); i++ { 188 if swag.IsZero(m.ResolvedIngredients[i]) { // not required 189 continue 190 } 191 192 if m.ResolvedIngredients[i] != nil { 193 if err := m.ResolvedIngredients[i].Validate(formats); err != nil { 194 if ve, ok := err.(*errors.Validation); ok { 195 return ve.ValidateName("resolved_ingredients" + "." + strconv.Itoa(i)) 196 } 197 return err 198 } 199 } 200 201 } 202 203 return nil 204 } 205 206 func (m *Recipe) validateSolverVersion(formats strfmt.Registry) error { 207 208 if err := validate.Required("solver_version", "body", m.SolverVersion); err != nil { 209 return err 210 } 211 212 return nil 213 } 214 215 // ContextValidate validate this recipe based on the context it is used 216 func (m *Recipe) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 217 var res []error 218 219 if err := m.contextValidateImage(ctx, formats); err != nil { 220 res = append(res, err) 221 } 222 223 if err := m.contextValidatePlatform(ctx, formats); err != nil { 224 res = append(res, err) 225 } 226 227 if err := m.contextValidateResolvedIngredients(ctx, formats); err != nil { 228 res = append(res, err) 229 } 230 231 if len(res) > 0 { 232 return errors.CompositeValidationError(res...) 233 } 234 return nil 235 } 236 237 func (m *Recipe) contextValidateImage(ctx context.Context, formats strfmt.Registry) error { 238 239 if m.Image != nil { 240 if err := m.Image.ContextValidate(ctx, formats); err != nil { 241 if ve, ok := err.(*errors.Validation); ok { 242 return ve.ValidateName("image") 243 } 244 return err 245 } 246 } 247 248 return nil 249 } 250 251 func (m *Recipe) contextValidatePlatform(ctx context.Context, formats strfmt.Registry) error { 252 253 if m.Platform != nil { 254 if err := m.Platform.ContextValidate(ctx, formats); err != nil { 255 if ve, ok := err.(*errors.Validation); ok { 256 return ve.ValidateName("platform") 257 } 258 return err 259 } 260 } 261 262 return nil 263 } 264 265 func (m *Recipe) contextValidateResolvedIngredients(ctx context.Context, formats strfmt.Registry) error { 266 267 for i := 0; i < len(m.ResolvedIngredients); i++ { 268 269 if m.ResolvedIngredients[i] != nil { 270 if err := m.ResolvedIngredients[i].ContextValidate(ctx, formats); err != nil { 271 if ve, ok := err.(*errors.Validation); ok { 272 return ve.ValidateName("resolved_ingredients" + "." + strconv.Itoa(i)) 273 } 274 return err 275 } 276 } 277 278 } 279 280 return nil 281 } 282 283 // MarshalBinary interface implementation 284 func (m *Recipe) MarshalBinary() ([]byte, error) { 285 if m == nil { 286 return nil, nil 287 } 288 return swag.WriteJSON(m) 289 } 290 291 // UnmarshalBinary interface implementation 292 func (m *Recipe) UnmarshalBinary(b []byte) error { 293 var res Recipe 294 if err := swag.ReadJSON(b, &res); err != nil { 295 return err 296 } 297 *m = res 298 return nil 299 }