github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/condition_set.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  // ConditionSet Condition Set
    19  //
    20  // All of the conditions in a condition set must be satisfied in order for the condition set to be considered satisfied (i.e. conditions in a condition set are ANDed together)
    21  //
    22  // swagger:model conditionSet
    23  type ConditionSet struct {
    24  
    25  	// The list of conditions that must all be satisfied for this condition set to be satisfied. These conditions may only condition on platform features, not ingredient features.
    26  	// Required: true
    27  	// Min Items: 1
    28  	Conditions []*Condition `json:"conditions"`
    29  }
    30  
    31  // Validate validates this condition set
    32  func (m *ConditionSet) Validate(formats strfmt.Registry) error {
    33  	var res []error
    34  
    35  	if err := m.validateConditions(formats); err != nil {
    36  		res = append(res, err)
    37  	}
    38  
    39  	if len(res) > 0 {
    40  		return errors.CompositeValidationError(res...)
    41  	}
    42  	return nil
    43  }
    44  
    45  func (m *ConditionSet) validateConditions(formats strfmt.Registry) error {
    46  
    47  	if err := validate.Required("conditions", "body", m.Conditions); err != nil {
    48  		return err
    49  	}
    50  
    51  	iConditionsSize := int64(len(m.Conditions))
    52  
    53  	if err := validate.MinItems("conditions", "body", iConditionsSize, 1); err != nil {
    54  		return err
    55  	}
    56  
    57  	for i := 0; i < len(m.Conditions); i++ {
    58  		if swag.IsZero(m.Conditions[i]) { // not required
    59  			continue
    60  		}
    61  
    62  		if m.Conditions[i] != nil {
    63  			if err := m.Conditions[i].Validate(formats); err != nil {
    64  				if ve, ok := err.(*errors.Validation); ok {
    65  					return ve.ValidateName("conditions" + "." + strconv.Itoa(i))
    66  				}
    67  				return err
    68  			}
    69  		}
    70  
    71  	}
    72  
    73  	return nil
    74  }
    75  
    76  // ContextValidate validate this condition set based on the context it is used
    77  func (m *ConditionSet) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    78  	var res []error
    79  
    80  	if err := m.contextValidateConditions(ctx, formats); err != nil {
    81  		res = append(res, err)
    82  	}
    83  
    84  	if len(res) > 0 {
    85  		return errors.CompositeValidationError(res...)
    86  	}
    87  	return nil
    88  }
    89  
    90  func (m *ConditionSet) contextValidateConditions(ctx context.Context, formats strfmt.Registry) error {
    91  
    92  	for i := 0; i < len(m.Conditions); i++ {
    93  
    94  		if m.Conditions[i] != nil {
    95  			if err := m.Conditions[i].ContextValidate(ctx, formats); err != nil {
    96  				if ve, ok := err.(*errors.Validation); ok {
    97  					return ve.ValidateName("conditions" + "." + strconv.Itoa(i))
    98  				}
    99  				return err
   100  			}
   101  		}
   102  
   103  	}
   104  
   105  	return nil
   106  }
   107  
   108  // MarshalBinary interface implementation
   109  func (m *ConditionSet) MarshalBinary() ([]byte, error) {
   110  	if m == nil {
   111  		return nil, nil
   112  	}
   113  	return swag.WriteJSON(m)
   114  }
   115  
   116  // UnmarshalBinary interface implementation
   117  func (m *ConditionSet) UnmarshalBinary(b []byte) error {
   118  	var res ConditionSet
   119  	if err := swag.ReadJSON(b, &res); err != nil {
   120  		return err
   121  	}
   122  	*m = res
   123  	return nil
   124  }