github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/requirements.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  // Requirements Requirements
    19  //
    20  // The version constraints that an ingredient version's requirement or condition puts on a feature
    21  //
    22  // swagger:model requirements
    23  type Requirements []*Requirement
    24  
    25  // Validate validates this requirements
    26  func (m Requirements) Validate(formats strfmt.Registry) error {
    27  	var res []error
    28  
    29  	iRequirementsSize := int64(len(m))
    30  
    31  	if err := validate.MinItems("", "body", iRequirementsSize, 1); err != nil {
    32  		return err
    33  	}
    34  
    35  	for i := 0; i < len(m); i++ {
    36  		if swag.IsZero(m[i]) { // not required
    37  			continue
    38  		}
    39  
    40  		if m[i] != nil {
    41  			if err := m[i].Validate(formats); err != nil {
    42  				if ve, ok := err.(*errors.Validation); ok {
    43  					return ve.ValidateName(strconv.Itoa(i))
    44  				}
    45  				return err
    46  			}
    47  		}
    48  
    49  	}
    50  
    51  	if len(res) > 0 {
    52  		return errors.CompositeValidationError(res...)
    53  	}
    54  	return nil
    55  }
    56  
    57  // ContextValidate validate this requirements based on the context it is used
    58  func (m Requirements) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    59  	var res []error
    60  
    61  	for i := 0; i < len(m); i++ {
    62  
    63  		if m[i] != nil {
    64  			if err := m[i].ContextValidate(ctx, formats); err != nil {
    65  				if ve, ok := err.(*errors.Validation); ok {
    66  					return ve.ValidateName(strconv.Itoa(i))
    67  				}
    68  				return err
    69  			}
    70  		}
    71  
    72  	}
    73  
    74  	if len(res) > 0 {
    75  		return errors.CompositeValidationError(res...)
    76  	}
    77  	return nil
    78  }