github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/payload_format.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  // PayloadFormat Webhook supported payload format type collections.
    18  //
    19  // swagger:model PayloadFormat
    20  type PayloadFormat struct {
    21  
    22  	// The supported payload formats for this notify type.
    23  	Formats []PayloadFormatType `json:"formats"`
    24  
    25  	// notify type
    26  	NotifyType NotifyType `json:"notify_type,omitempty"`
    27  }
    28  
    29  // Validate validates this payload format
    30  func (m *PayloadFormat) Validate(formats strfmt.Registry) error {
    31  	var res []error
    32  
    33  	if err := m.validateFormats(formats); err != nil {
    34  		res = append(res, err)
    35  	}
    36  
    37  	if err := m.validateNotifyType(formats); err != nil {
    38  		res = append(res, err)
    39  	}
    40  
    41  	if len(res) > 0 {
    42  		return errors.CompositeValidationError(res...)
    43  	}
    44  	return nil
    45  }
    46  
    47  func (m *PayloadFormat) validateFormats(formats strfmt.Registry) error {
    48  	if swag.IsZero(m.Formats) { // not required
    49  		return nil
    50  	}
    51  
    52  	for i := 0; i < len(m.Formats); i++ {
    53  
    54  		if err := m.Formats[i].Validate(formats); err != nil {
    55  			if ve, ok := err.(*errors.Validation); ok {
    56  				return ve.ValidateName("formats" + "." + strconv.Itoa(i))
    57  			} else if ce, ok := err.(*errors.CompositeError); ok {
    58  				return ce.ValidateName("formats" + "." + strconv.Itoa(i))
    59  			}
    60  			return err
    61  		}
    62  
    63  	}
    64  
    65  	return nil
    66  }
    67  
    68  func (m *PayloadFormat) validateNotifyType(formats strfmt.Registry) error {
    69  	if swag.IsZero(m.NotifyType) { // not required
    70  		return nil
    71  	}
    72  
    73  	if err := m.NotifyType.Validate(formats); err != nil {
    74  		if ve, ok := err.(*errors.Validation); ok {
    75  			return ve.ValidateName("notify_type")
    76  		} else if ce, ok := err.(*errors.CompositeError); ok {
    77  			return ce.ValidateName("notify_type")
    78  		}
    79  		return err
    80  	}
    81  
    82  	return nil
    83  }
    84  
    85  // ContextValidate validate this payload format based on the context it is used
    86  func (m *PayloadFormat) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    87  	var res []error
    88  
    89  	if err := m.contextValidateFormats(ctx, formats); err != nil {
    90  		res = append(res, err)
    91  	}
    92  
    93  	if err := m.contextValidateNotifyType(ctx, formats); err != nil {
    94  		res = append(res, err)
    95  	}
    96  
    97  	if len(res) > 0 {
    98  		return errors.CompositeValidationError(res...)
    99  	}
   100  	return nil
   101  }
   102  
   103  func (m *PayloadFormat) contextValidateFormats(ctx context.Context, formats strfmt.Registry) error {
   104  
   105  	for i := 0; i < len(m.Formats); i++ {
   106  
   107  		if err := m.Formats[i].ContextValidate(ctx, formats); err != nil {
   108  			if ve, ok := err.(*errors.Validation); ok {
   109  				return ve.ValidateName("formats" + "." + strconv.Itoa(i))
   110  			} else if ce, ok := err.(*errors.CompositeError); ok {
   111  				return ce.ValidateName("formats" + "." + strconv.Itoa(i))
   112  			}
   113  			return err
   114  		}
   115  
   116  	}
   117  
   118  	return nil
   119  }
   120  
   121  func (m *PayloadFormat) contextValidateNotifyType(ctx context.Context, formats strfmt.Registry) error {
   122  
   123  	if err := m.NotifyType.ContextValidate(ctx, formats); err != nil {
   124  		if ve, ok := err.(*errors.Validation); ok {
   125  			return ve.ValidateName("notify_type")
   126  		} else if ce, ok := err.(*errors.CompositeError); ok {
   127  			return ce.ValidateName("notify_type")
   128  		}
   129  		return err
   130  	}
   131  
   132  	return nil
   133  }
   134  
   135  // MarshalBinary interface implementation
   136  func (m *PayloadFormat) MarshalBinary() ([]byte, error) {
   137  	if m == nil {
   138  		return nil, nil
   139  	}
   140  	return swag.WriteJSON(m)
   141  }
   142  
   143  // UnmarshalBinary interface implementation
   144  func (m *PayloadFormat) UnmarshalBinary(b []byte) error {
   145  	var res PayloadFormat
   146  	if err := swag.ReadJSON(b, &res); err != nil {
   147  		return err
   148  	}
   149  	*m = res
   150  	return nil
   151  }