github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/robot_create_v1.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package 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  )
    16  
    17  // RobotCreateV1 robot create v1
    18  //
    19  // swagger:model RobotCreateV1
    20  type RobotCreateV1 struct {
    21  
    22  	// The permission of robot account
    23  	Access []*Access `json:"access"`
    24  
    25  	// The description of robot account
    26  	Description string `json:"description,omitempty"`
    27  
    28  	// The expiration time on or after which the JWT MUST NOT be accepted for processing.
    29  	ExpiresAt int64 `json:"expires_at,omitempty"`
    30  
    31  	// The name of robot account
    32  	Name string `json:"name,omitempty"`
    33  }
    34  
    35  // Validate validates this robot create v1
    36  func (m *RobotCreateV1) Validate(formats strfmt.Registry) error {
    37  	var res []error
    38  
    39  	if err := m.validateAccess(formats); err != nil {
    40  		res = append(res, err)
    41  	}
    42  
    43  	if len(res) > 0 {
    44  		return errors.CompositeValidationError(res...)
    45  	}
    46  	return nil
    47  }
    48  
    49  func (m *RobotCreateV1) validateAccess(formats strfmt.Registry) error {
    50  	if swag.IsZero(m.Access) { // not required
    51  		return nil
    52  	}
    53  
    54  	for i := 0; i < len(m.Access); i++ {
    55  		if swag.IsZero(m.Access[i]) { // not required
    56  			continue
    57  		}
    58  
    59  		if m.Access[i] != nil {
    60  			if err := m.Access[i].Validate(formats); err != nil {
    61  				if ve, ok := err.(*errors.Validation); ok {
    62  					return ve.ValidateName("access" + "." + strconv.Itoa(i))
    63  				} else if ce, ok := err.(*errors.CompositeError); ok {
    64  					return ce.ValidateName("access" + "." + strconv.Itoa(i))
    65  				}
    66  				return err
    67  			}
    68  		}
    69  
    70  	}
    71  
    72  	return nil
    73  }
    74  
    75  // ContextValidate validate this robot create v1 based on the context it is used
    76  func (m *RobotCreateV1) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.contextValidateAccess(ctx, formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if len(res) > 0 {
    84  		return errors.CompositeValidationError(res...)
    85  	}
    86  	return nil
    87  }
    88  
    89  func (m *RobotCreateV1) contextValidateAccess(ctx context.Context, formats strfmt.Registry) error {
    90  
    91  	for i := 0; i < len(m.Access); i++ {
    92  
    93  		if m.Access[i] != nil {
    94  			if err := m.Access[i].ContextValidate(ctx, formats); err != nil {
    95  				if ve, ok := err.(*errors.Validation); ok {
    96  					return ve.ValidateName("access" + "." + strconv.Itoa(i))
    97  				} else if ce, ok := err.(*errors.CompositeError); ok {
    98  					return ce.ValidateName("access" + "." + strconv.Itoa(i))
    99  				}
   100  				return err
   101  			}
   102  		}
   103  
   104  	}
   105  
   106  	return nil
   107  }
   108  
   109  // MarshalBinary interface implementation
   110  func (m *RobotCreateV1) MarshalBinary() ([]byte, error) {
   111  	if m == nil {
   112  		return nil, nil
   113  	}
   114  	return swag.WriteJSON(m)
   115  }
   116  
   117  // UnmarshalBinary interface implementation
   118  func (m *RobotCreateV1) UnmarshalBinary(b []byte) error {
   119  	var res RobotCreateV1
   120  	if err := swag.ReadJSON(b, &res); err != nil {
   121  		return err
   122  	}
   123  	*m = res
   124  	return nil
   125  }