github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/version_info.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  // VersionInfo Version Info
    19  //
    20  // Properties shared by all versioned resources
    21  //
    22  // swagger:model versionInfo
    23  type VersionInfo struct {
    24  
    25  	// 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.
    26  	SortableVersion []string `json:"sortable_version"`
    27  
    28  	// The canonical version string for the resource. Should be as specific as possible (e.g. '10.9.6' of macOS instead of just '10.9'). May contain non-numeric version segments and other formatting characters if necessary.
    29  	// Required: true
    30  	Version *string `json:"version"`
    31  }
    32  
    33  // Validate validates this version info
    34  func (m *VersionInfo) Validate(formats strfmt.Registry) error {
    35  	var res []error
    36  
    37  	if err := m.validateSortableVersion(formats); err != nil {
    38  		res = append(res, err)
    39  	}
    40  
    41  	if err := m.validateVersion(formats); err != nil {
    42  		res = append(res, err)
    43  	}
    44  
    45  	if len(res) > 0 {
    46  		return errors.CompositeValidationError(res...)
    47  	}
    48  	return nil
    49  }
    50  
    51  func (m *VersionInfo) validateSortableVersion(formats strfmt.Registry) error {
    52  	if swag.IsZero(m.SortableVersion) { // not required
    53  		return nil
    54  	}
    55  
    56  	for i := 0; i < len(m.SortableVersion); i++ {
    57  
    58  		if err := validate.MinLength("sortable_version"+"."+strconv.Itoa(i), "body", m.SortableVersion[i], 1); err != nil {
    59  			return err
    60  		}
    61  
    62  	}
    63  
    64  	return nil
    65  }
    66  
    67  func (m *VersionInfo) validateVersion(formats strfmt.Registry) error {
    68  
    69  	if err := validate.Required("version", "body", m.Version); err != nil {
    70  		return err
    71  	}
    72  
    73  	return nil
    74  }
    75  
    76  // ContextValidate validates this version info based on context it is used
    77  func (m *VersionInfo) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    78  	return nil
    79  }
    80  
    81  // MarshalBinary interface implementation
    82  func (m *VersionInfo) MarshalBinary() ([]byte, error) {
    83  	if m == nil {
    84  		return nil, nil
    85  	}
    86  	return swag.WriteJSON(m)
    87  }
    88  
    89  // UnmarshalBinary interface implementation
    90  func (m *VersionInfo) UnmarshalBinary(b []byte) error {
    91  	var res VersionInfo
    92  	if err := swag.ReadJSON(b, &res); err != nil {
    93  		return err
    94  	}
    95  	*m = res
    96  	return nil
    97  }