github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/dependency.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  // Dependency Dependency
    19  //
    20  // A single dependency for an ingredient version revision
    21  //
    22  // swagger:model dependency
    23  type Dependency struct {
    24  
    25  	// The features that must already be present in the recipe for this requirement to apply. For example, can be used to create requirements that only apply on specific operating systems.
    26  	Conditions []*DependencyCondition `json:"conditions"`
    27  
    28  	// A description of this dependency
    29  	Description string `json:"description,omitempty"`
    30  
    31  	// The name of the feature this ingredient version is dependent on
    32  	// Required: true
    33  	Feature *string `json:"feature"`
    34  
    35  	// The namespace the feature depended on is contained in
    36  	// Required: true
    37  	Namespace *string `json:"namespace"`
    38  
    39  	// Whatever text or data structure we parsed to generate this dependency
    40  	OriginalRequirement string `json:"original_requirement,omitempty"`
    41  
    42  	// requirements
    43  	// Required: true
    44  	Requirements Requirements `json:"requirements"`
    45  
    46  	// type
    47  	// Required: true
    48  	Type DependencyType `json:"type"`
    49  }
    50  
    51  // Validate validates this dependency
    52  func (m *Dependency) Validate(formats strfmt.Registry) error {
    53  	var res []error
    54  
    55  	if err := m.validateConditions(formats); err != nil {
    56  		res = append(res, err)
    57  	}
    58  
    59  	if err := m.validateFeature(formats); err != nil {
    60  		res = append(res, err)
    61  	}
    62  
    63  	if err := m.validateNamespace(formats); err != nil {
    64  		res = append(res, err)
    65  	}
    66  
    67  	if err := m.validateRequirements(formats); err != nil {
    68  		res = append(res, err)
    69  	}
    70  
    71  	if err := m.validateType(formats); err != nil {
    72  		res = append(res, err)
    73  	}
    74  
    75  	if len(res) > 0 {
    76  		return errors.CompositeValidationError(res...)
    77  	}
    78  	return nil
    79  }
    80  
    81  func (m *Dependency) validateConditions(formats strfmt.Registry) error {
    82  	if swag.IsZero(m.Conditions) { // not required
    83  		return nil
    84  	}
    85  
    86  	for i := 0; i < len(m.Conditions); i++ {
    87  		if swag.IsZero(m.Conditions[i]) { // not required
    88  			continue
    89  		}
    90  
    91  		if m.Conditions[i] != nil {
    92  			if err := m.Conditions[i].Validate(formats); err != nil {
    93  				if ve, ok := err.(*errors.Validation); ok {
    94  					return ve.ValidateName("conditions" + "." + strconv.Itoa(i))
    95  				}
    96  				return err
    97  			}
    98  		}
    99  
   100  	}
   101  
   102  	return nil
   103  }
   104  
   105  func (m *Dependency) validateFeature(formats strfmt.Registry) error {
   106  
   107  	if err := validate.Required("feature", "body", m.Feature); err != nil {
   108  		return err
   109  	}
   110  
   111  	return nil
   112  }
   113  
   114  func (m *Dependency) validateNamespace(formats strfmt.Registry) error {
   115  
   116  	if err := validate.Required("namespace", "body", m.Namespace); err != nil {
   117  		return err
   118  	}
   119  
   120  	return nil
   121  }
   122  
   123  func (m *Dependency) validateRequirements(formats strfmt.Registry) error {
   124  
   125  	if err := validate.Required("requirements", "body", m.Requirements); err != nil {
   126  		return err
   127  	}
   128  
   129  	if err := m.Requirements.Validate(formats); err != nil {
   130  		if ve, ok := err.(*errors.Validation); ok {
   131  			return ve.ValidateName("requirements")
   132  		}
   133  		return err
   134  	}
   135  
   136  	return nil
   137  }
   138  
   139  func (m *Dependency) validateType(formats strfmt.Registry) error {
   140  
   141  	if err := validate.Required("type", "body", DependencyType(m.Type)); err != nil {
   142  		return err
   143  	}
   144  
   145  	if err := m.Type.Validate(formats); err != nil {
   146  		if ve, ok := err.(*errors.Validation); ok {
   147  			return ve.ValidateName("type")
   148  		}
   149  		return err
   150  	}
   151  
   152  	return nil
   153  }
   154  
   155  // ContextValidate validate this dependency based on the context it is used
   156  func (m *Dependency) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   157  	var res []error
   158  
   159  	if err := m.contextValidateConditions(ctx, formats); err != nil {
   160  		res = append(res, err)
   161  	}
   162  
   163  	if err := m.contextValidateRequirements(ctx, formats); err != nil {
   164  		res = append(res, err)
   165  	}
   166  
   167  	if err := m.contextValidateType(ctx, formats); err != nil {
   168  		res = append(res, err)
   169  	}
   170  
   171  	if len(res) > 0 {
   172  		return errors.CompositeValidationError(res...)
   173  	}
   174  	return nil
   175  }
   176  
   177  func (m *Dependency) contextValidateConditions(ctx context.Context, formats strfmt.Registry) error {
   178  
   179  	for i := 0; i < len(m.Conditions); i++ {
   180  
   181  		if m.Conditions[i] != nil {
   182  			if err := m.Conditions[i].ContextValidate(ctx, formats); err != nil {
   183  				if ve, ok := err.(*errors.Validation); ok {
   184  					return ve.ValidateName("conditions" + "." + strconv.Itoa(i))
   185  				}
   186  				return err
   187  			}
   188  		}
   189  
   190  	}
   191  
   192  	return nil
   193  }
   194  
   195  func (m *Dependency) contextValidateRequirements(ctx context.Context, formats strfmt.Registry) error {
   196  
   197  	if err := m.Requirements.ContextValidate(ctx, formats); err != nil {
   198  		if ve, ok := err.(*errors.Validation); ok {
   199  			return ve.ValidateName("requirements")
   200  		}
   201  		return err
   202  	}
   203  
   204  	return nil
   205  }
   206  
   207  func (m *Dependency) contextValidateType(ctx context.Context, formats strfmt.Registry) error {
   208  
   209  	if err := m.Type.ContextValidate(ctx, formats); err != nil {
   210  		if ve, ok := err.(*errors.Validation); ok {
   211  			return ve.ValidateName("type")
   212  		}
   213  		return err
   214  	}
   215  
   216  	return nil
   217  }
   218  
   219  // MarshalBinary interface implementation
   220  func (m *Dependency) MarshalBinary() ([]byte, error) {
   221  	if m == nil {
   222  		return nil, nil
   223  	}
   224  	return swag.WriteJSON(m)
   225  }
   226  
   227  // UnmarshalBinary interface implementation
   228  func (m *Dependency) UnmarshalBinary(b []byte) error {
   229  	var res Dependency
   230  	if err := swag.ReadJSON(b, &res); err != nil {
   231  		return err
   232  	}
   233  	*m = res
   234  	return nil
   235  }