github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/condition.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 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/strfmt" 13 "github.com/go-openapi/swag" 14 "github.com/go-openapi/validate" 15 ) 16 17 // Condition Condition 18 // 19 // A feature that must be present in a recipe for the containing entity to apply. If nothing in the recipe matches this condition, the containing entity is disable/cannot be used. 20 // 21 // swagger:model condition 22 type Condition struct { 23 24 // What feature must be present for the containing entity to apply 25 // Required: true 26 Feature *string `json:"feature"` 27 28 // The namespace the conditional feature is contained in 29 // Required: true 30 Namespace *string `json:"namespace"` 31 32 // requirements 33 // Required: true 34 Requirements Requirements `json:"requirements"` 35 } 36 37 // Validate validates this condition 38 func (m *Condition) Validate(formats strfmt.Registry) error { 39 var res []error 40 41 if err := m.validateFeature(formats); err != nil { 42 res = append(res, err) 43 } 44 45 if err := m.validateNamespace(formats); err != nil { 46 res = append(res, err) 47 } 48 49 if err := m.validateRequirements(formats); err != nil { 50 res = append(res, err) 51 } 52 53 if len(res) > 0 { 54 return errors.CompositeValidationError(res...) 55 } 56 return nil 57 } 58 59 func (m *Condition) validateFeature(formats strfmt.Registry) error { 60 61 if err := validate.Required("feature", "body", m.Feature); err != nil { 62 return err 63 } 64 65 return nil 66 } 67 68 func (m *Condition) validateNamespace(formats strfmt.Registry) error { 69 70 if err := validate.Required("namespace", "body", m.Namespace); err != nil { 71 return err 72 } 73 74 return nil 75 } 76 77 func (m *Condition) validateRequirements(formats strfmt.Registry) error { 78 79 if err := validate.Required("requirements", "body", m.Requirements); err != nil { 80 return err 81 } 82 83 if err := m.Requirements.Validate(formats); err != nil { 84 if ve, ok := err.(*errors.Validation); ok { 85 return ve.ValidateName("requirements") 86 } 87 return err 88 } 89 90 return nil 91 } 92 93 // ContextValidate validate this condition based on the context it is used 94 func (m *Condition) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 95 var res []error 96 97 if err := m.contextValidateRequirements(ctx, formats); err != nil { 98 res = append(res, err) 99 } 100 101 if len(res) > 0 { 102 return errors.CompositeValidationError(res...) 103 } 104 return nil 105 } 106 107 func (m *Condition) contextValidateRequirements(ctx context.Context, formats strfmt.Registry) error { 108 109 if err := m.Requirements.ContextValidate(ctx, formats); err != nil { 110 if ve, ok := err.(*errors.Validation); ok { 111 return ve.ValidateName("requirements") 112 } 113 return err 114 } 115 116 return nil 117 } 118 119 // MarshalBinary interface implementation 120 func (m *Condition) MarshalBinary() ([]byte, error) { 121 if m == nil { 122 return nil, nil 123 } 124 return swag.WriteJSON(m) 125 } 126 127 // UnmarshalBinary interface implementation 128 func (m *Condition) UnmarshalBinary(b []byte) error { 129 var res Condition 130 if err := swag.ReadJSON(b, &res); err != nil { 131 return err 132 } 133 *m = res 134 return nil 135 }