github.com/digitalocean/go-netbox@v0.0.2/netbox/models/virtual_chassis.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright 2020 The go-netbox Authors.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //   http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  //
    17  
    18  package models
    19  
    20  // This file was generated by the swagger tool.
    21  // Editing this file might prove futile when you re-run the swagger generate command
    22  
    23  import (
    24  	"context"
    25  	"strconv"
    26  
    27  	"github.com/go-openapi/errors"
    28  	"github.com/go-openapi/strfmt"
    29  	"github.com/go-openapi/swag"
    30  	"github.com/go-openapi/validate"
    31  )
    32  
    33  // VirtualChassis virtual chassis
    34  //
    35  // swagger:model VirtualChassis
    36  type VirtualChassis struct {
    37  
    38  	// Custom fields
    39  	CustomFields interface{} `json:"custom_fields,omitempty"`
    40  
    41  	// Display
    42  	// Read Only: true
    43  	Display string `json:"display,omitempty"`
    44  
    45  	// Domain
    46  	// Max Length: 30
    47  	Domain string `json:"domain,omitempty"`
    48  
    49  	// Id
    50  	// Read Only: true
    51  	ID int64 `json:"id,omitempty"`
    52  
    53  	// master
    54  	Master *NestedDevice `json:"master,omitempty"`
    55  
    56  	// Member count
    57  	// Read Only: true
    58  	MemberCount int64 `json:"member_count,omitempty"`
    59  
    60  	// Name
    61  	// Required: true
    62  	// Max Length: 64
    63  	// Min Length: 1
    64  	Name *string `json:"name"`
    65  
    66  	// tags
    67  	Tags []*NestedTag `json:"tags"`
    68  
    69  	// Url
    70  	// Read Only: true
    71  	// Format: uri
    72  	URL strfmt.URI `json:"url,omitempty"`
    73  }
    74  
    75  // Validate validates this virtual chassis
    76  func (m *VirtualChassis) Validate(formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.validateDomain(formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if err := m.validateMaster(formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	if err := m.validateName(formats); err != nil {
    88  		res = append(res, err)
    89  	}
    90  
    91  	if err := m.validateTags(formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if err := m.validateURL(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if len(res) > 0 {
   100  		return errors.CompositeValidationError(res...)
   101  	}
   102  	return nil
   103  }
   104  
   105  func (m *VirtualChassis) validateDomain(formats strfmt.Registry) error {
   106  	if swag.IsZero(m.Domain) { // not required
   107  		return nil
   108  	}
   109  
   110  	if err := validate.MaxLength("domain", "body", m.Domain, 30); err != nil {
   111  		return err
   112  	}
   113  
   114  	return nil
   115  }
   116  
   117  func (m *VirtualChassis) validateMaster(formats strfmt.Registry) error {
   118  	if swag.IsZero(m.Master) { // not required
   119  		return nil
   120  	}
   121  
   122  	if m.Master != nil {
   123  		if err := m.Master.Validate(formats); err != nil {
   124  			if ve, ok := err.(*errors.Validation); ok {
   125  				return ve.ValidateName("master")
   126  			} else if ce, ok := err.(*errors.CompositeError); ok {
   127  				return ce.ValidateName("master")
   128  			}
   129  			return err
   130  		}
   131  	}
   132  
   133  	return nil
   134  }
   135  
   136  func (m *VirtualChassis) validateName(formats strfmt.Registry) error {
   137  
   138  	if err := validate.Required("name", "body", m.Name); err != nil {
   139  		return err
   140  	}
   141  
   142  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   143  		return err
   144  	}
   145  
   146  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   147  		return err
   148  	}
   149  
   150  	return nil
   151  }
   152  
   153  func (m *VirtualChassis) validateTags(formats strfmt.Registry) error {
   154  	if swag.IsZero(m.Tags) { // not required
   155  		return nil
   156  	}
   157  
   158  	for i := 0; i < len(m.Tags); i++ {
   159  		if swag.IsZero(m.Tags[i]) { // not required
   160  			continue
   161  		}
   162  
   163  		if m.Tags[i] != nil {
   164  			if err := m.Tags[i].Validate(formats); err != nil {
   165  				if ve, ok := err.(*errors.Validation); ok {
   166  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   167  				} else if ce, ok := err.(*errors.CompositeError); ok {
   168  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   169  				}
   170  				return err
   171  			}
   172  		}
   173  
   174  	}
   175  
   176  	return nil
   177  }
   178  
   179  func (m *VirtualChassis) validateURL(formats strfmt.Registry) error {
   180  	if swag.IsZero(m.URL) { // not required
   181  		return nil
   182  	}
   183  
   184  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   185  		return err
   186  	}
   187  
   188  	return nil
   189  }
   190  
   191  // ContextValidate validate this virtual chassis based on the context it is used
   192  func (m *VirtualChassis) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   193  	var res []error
   194  
   195  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   196  		res = append(res, err)
   197  	}
   198  
   199  	if err := m.contextValidateID(ctx, formats); err != nil {
   200  		res = append(res, err)
   201  	}
   202  
   203  	if err := m.contextValidateMaster(ctx, formats); err != nil {
   204  		res = append(res, err)
   205  	}
   206  
   207  	if err := m.contextValidateMemberCount(ctx, formats); err != nil {
   208  		res = append(res, err)
   209  	}
   210  
   211  	if err := m.contextValidateTags(ctx, formats); err != nil {
   212  		res = append(res, err)
   213  	}
   214  
   215  	if err := m.contextValidateURL(ctx, formats); err != nil {
   216  		res = append(res, err)
   217  	}
   218  
   219  	if len(res) > 0 {
   220  		return errors.CompositeValidationError(res...)
   221  	}
   222  	return nil
   223  }
   224  
   225  func (m *VirtualChassis) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   226  
   227  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   228  		return err
   229  	}
   230  
   231  	return nil
   232  }
   233  
   234  func (m *VirtualChassis) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   235  
   236  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   237  		return err
   238  	}
   239  
   240  	return nil
   241  }
   242  
   243  func (m *VirtualChassis) contextValidateMaster(ctx context.Context, formats strfmt.Registry) error {
   244  
   245  	if m.Master != nil {
   246  		if err := m.Master.ContextValidate(ctx, formats); err != nil {
   247  			if ve, ok := err.(*errors.Validation); ok {
   248  				return ve.ValidateName("master")
   249  			} else if ce, ok := err.(*errors.CompositeError); ok {
   250  				return ce.ValidateName("master")
   251  			}
   252  			return err
   253  		}
   254  	}
   255  
   256  	return nil
   257  }
   258  
   259  func (m *VirtualChassis) contextValidateMemberCount(ctx context.Context, formats strfmt.Registry) error {
   260  
   261  	if err := validate.ReadOnly(ctx, "member_count", "body", int64(m.MemberCount)); err != nil {
   262  		return err
   263  	}
   264  
   265  	return nil
   266  }
   267  
   268  func (m *VirtualChassis) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   269  
   270  	for i := 0; i < len(m.Tags); i++ {
   271  
   272  		if m.Tags[i] != nil {
   273  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   274  				if ve, ok := err.(*errors.Validation); ok {
   275  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   276  				} else if ce, ok := err.(*errors.CompositeError); ok {
   277  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   278  				}
   279  				return err
   280  			}
   281  		}
   282  
   283  	}
   284  
   285  	return nil
   286  }
   287  
   288  func (m *VirtualChassis) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   289  
   290  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   291  		return err
   292  	}
   293  
   294  	return nil
   295  }
   296  
   297  // MarshalBinary interface implementation
   298  func (m *VirtualChassis) MarshalBinary() ([]byte, error) {
   299  	if m == nil {
   300  		return nil, nil
   301  	}
   302  	return swag.WriteJSON(m)
   303  }
   304  
   305  // UnmarshalBinary interface implementation
   306  func (m *VirtualChassis) UnmarshalBinary(b []byte) error {
   307  	var res VirtualChassis
   308  	if err := swag.ReadJSON(b, &res); err != nil {
   309  		return err
   310  	}
   311  	*m = res
   312  	return nil
   313  }