github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/requirement.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  	"encoding/json"
    11  	"strconv"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/strfmt"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/go-openapi/validate"
    17  )
    18  
    19  // Requirement Requirement
    20  //
    21  // swagger:model requirement
    22  type Requirement struct {
    23  
    24  	// The operator used to compare the sortable_version against a given provided feature to determine if it meets the requirement
    25  	// Required: true
    26  	// Enum: [eq gt gte lt lte ne]
    27  	Comparator *string `json:"comparator"`
    28  
    29  	// An array of decimal values representing all segments of a version, ordered from most to least significant. How a version string is rendered into a list of decimals will vary depending on the format of the source string and is therefore left up to the caller, but it must be done consistently across all versions of the same resource for sorting to work properly. This is represented as a string to avoid losing precision when converting to a floating point number.
    30  	SortableVersion []string `json:"sortable_version"`
    31  
    32  	// The required version in its original form.
    33  	// Min Length: 1
    34  	Version *string `json:"version,omitempty"`
    35  }
    36  
    37  // Validate validates this requirement
    38  func (m *Requirement) Validate(formats strfmt.Registry) error {
    39  	var res []error
    40  
    41  	if err := m.validateComparator(formats); err != nil {
    42  		res = append(res, err)
    43  	}
    44  
    45  	if err := m.validateSortableVersion(formats); err != nil {
    46  		res = append(res, err)
    47  	}
    48  
    49  	if err := m.validateVersion(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  var requirementTypeComparatorPropEnum []interface{}
    60  
    61  func init() {
    62  	var res []string
    63  	if err := json.Unmarshal([]byte(`["eq","gt","gte","lt","lte","ne"]`), &res); err != nil {
    64  		panic(err)
    65  	}
    66  	for _, v := range res {
    67  		requirementTypeComparatorPropEnum = append(requirementTypeComparatorPropEnum, v)
    68  	}
    69  }
    70  
    71  const (
    72  
    73  	// RequirementComparatorEq captures enum value "eq"
    74  	RequirementComparatorEq string = "eq"
    75  
    76  	// RequirementComparatorGt captures enum value "gt"
    77  	RequirementComparatorGt string = "gt"
    78  
    79  	// RequirementComparatorGte captures enum value "gte"
    80  	RequirementComparatorGte string = "gte"
    81  
    82  	// RequirementComparatorLt captures enum value "lt"
    83  	RequirementComparatorLt string = "lt"
    84  
    85  	// RequirementComparatorLte captures enum value "lte"
    86  	RequirementComparatorLte string = "lte"
    87  
    88  	// RequirementComparatorNe captures enum value "ne"
    89  	RequirementComparatorNe string = "ne"
    90  )
    91  
    92  // prop value enum
    93  func (m *Requirement) validateComparatorEnum(path, location string, value string) error {
    94  	if err := validate.EnumCase(path, location, value, requirementTypeComparatorPropEnum, true); err != nil {
    95  		return err
    96  	}
    97  	return nil
    98  }
    99  
   100  func (m *Requirement) validateComparator(formats strfmt.Registry) error {
   101  
   102  	if err := validate.Required("comparator", "body", m.Comparator); err != nil {
   103  		return err
   104  	}
   105  
   106  	// value enum
   107  	if err := m.validateComparatorEnum("comparator", "body", *m.Comparator); err != nil {
   108  		return err
   109  	}
   110  
   111  	return nil
   112  }
   113  
   114  func (m *Requirement) validateSortableVersion(formats strfmt.Registry) error {
   115  	if swag.IsZero(m.SortableVersion) { // not required
   116  		return nil
   117  	}
   118  
   119  	for i := 0; i < len(m.SortableVersion); i++ {
   120  
   121  		if err := validate.MinLength("sortable_version"+"."+strconv.Itoa(i), "body", m.SortableVersion[i], 1); err != nil {
   122  			return err
   123  		}
   124  
   125  	}
   126  
   127  	return nil
   128  }
   129  
   130  func (m *Requirement) validateVersion(formats strfmt.Registry) error {
   131  	if swag.IsZero(m.Version) { // not required
   132  		return nil
   133  	}
   134  
   135  	if err := validate.MinLength("version", "body", *m.Version, 1); err != nil {
   136  		return err
   137  	}
   138  
   139  	return nil
   140  }
   141  
   142  // ContextValidate validates this requirement based on context it is used
   143  func (m *Requirement) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   144  	return nil
   145  }
   146  
   147  // MarshalBinary interface implementation
   148  func (m *Requirement) MarshalBinary() ([]byte, error) {
   149  	if m == nil {
   150  		return nil, nil
   151  	}
   152  	return swag.WriteJSON(m)
   153  }
   154  
   155  // UnmarshalBinary interface implementation
   156  func (m *Requirement) UnmarshalBinary(b []byte) error {
   157  	var res Requirement
   158  	if err := swag.ReadJSON(b, &res); err != nil {
   159  		return err
   160  	}
   161  	*m = res
   162  	return nil
   163  }