github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_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  // WritableVirtualChassis writable virtual chassis
    34  //
    35  // swagger:model WritableVirtualChassis
    36  type WritableVirtualChassis 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 *int64 `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 writable virtual chassis
    76  func (m *WritableVirtualChassis) 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.validateName(formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	if err := m.validateTags(formats); err != nil {
    88  		res = append(res, err)
    89  	}
    90  
    91  	if err := m.validateURL(formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if len(res) > 0 {
    96  		return errors.CompositeValidationError(res...)
    97  	}
    98  	return nil
    99  }
   100  
   101  func (m *WritableVirtualChassis) validateDomain(formats strfmt.Registry) error {
   102  	if swag.IsZero(m.Domain) { // not required
   103  		return nil
   104  	}
   105  
   106  	if err := validate.MaxLength("domain", "body", m.Domain, 30); err != nil {
   107  		return err
   108  	}
   109  
   110  	return nil
   111  }
   112  
   113  func (m *WritableVirtualChassis) validateName(formats strfmt.Registry) error {
   114  
   115  	if err := validate.Required("name", "body", m.Name); err != nil {
   116  		return err
   117  	}
   118  
   119  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   120  		return err
   121  	}
   122  
   123  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   124  		return err
   125  	}
   126  
   127  	return nil
   128  }
   129  
   130  func (m *WritableVirtualChassis) validateTags(formats strfmt.Registry) error {
   131  	if swag.IsZero(m.Tags) { // not required
   132  		return nil
   133  	}
   134  
   135  	for i := 0; i < len(m.Tags); i++ {
   136  		if swag.IsZero(m.Tags[i]) { // not required
   137  			continue
   138  		}
   139  
   140  		if m.Tags[i] != nil {
   141  			if err := m.Tags[i].Validate(formats); err != nil {
   142  				if ve, ok := err.(*errors.Validation); ok {
   143  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   144  				} else if ce, ok := err.(*errors.CompositeError); ok {
   145  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   146  				}
   147  				return err
   148  			}
   149  		}
   150  
   151  	}
   152  
   153  	return nil
   154  }
   155  
   156  func (m *WritableVirtualChassis) validateURL(formats strfmt.Registry) error {
   157  	if swag.IsZero(m.URL) { // not required
   158  		return nil
   159  	}
   160  
   161  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   162  		return err
   163  	}
   164  
   165  	return nil
   166  }
   167  
   168  // ContextValidate validate this writable virtual chassis based on the context it is used
   169  func (m *WritableVirtualChassis) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   170  	var res []error
   171  
   172  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   173  		res = append(res, err)
   174  	}
   175  
   176  	if err := m.contextValidateID(ctx, formats); err != nil {
   177  		res = append(res, err)
   178  	}
   179  
   180  	if err := m.contextValidateMemberCount(ctx, formats); err != nil {
   181  		res = append(res, err)
   182  	}
   183  
   184  	if err := m.contextValidateTags(ctx, formats); err != nil {
   185  		res = append(res, err)
   186  	}
   187  
   188  	if err := m.contextValidateURL(ctx, formats); err != nil {
   189  		res = append(res, err)
   190  	}
   191  
   192  	if len(res) > 0 {
   193  		return errors.CompositeValidationError(res...)
   194  	}
   195  	return nil
   196  }
   197  
   198  func (m *WritableVirtualChassis) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   199  
   200  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   201  		return err
   202  	}
   203  
   204  	return nil
   205  }
   206  
   207  func (m *WritableVirtualChassis) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   208  
   209  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   210  		return err
   211  	}
   212  
   213  	return nil
   214  }
   215  
   216  func (m *WritableVirtualChassis) contextValidateMemberCount(ctx context.Context, formats strfmt.Registry) error {
   217  
   218  	if err := validate.ReadOnly(ctx, "member_count", "body", int64(m.MemberCount)); err != nil {
   219  		return err
   220  	}
   221  
   222  	return nil
   223  }
   224  
   225  func (m *WritableVirtualChassis) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   226  
   227  	for i := 0; i < len(m.Tags); i++ {
   228  
   229  		if m.Tags[i] != nil {
   230  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   231  				if ve, ok := err.(*errors.Validation); ok {
   232  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   233  				} else if ce, ok := err.(*errors.CompositeError); ok {
   234  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   235  				}
   236  				return err
   237  			}
   238  		}
   239  
   240  	}
   241  
   242  	return nil
   243  }
   244  
   245  func (m *WritableVirtualChassis) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   246  
   247  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   248  		return err
   249  	}
   250  
   251  	return nil
   252  }
   253  
   254  // MarshalBinary interface implementation
   255  func (m *WritableVirtualChassis) MarshalBinary() ([]byte, error) {
   256  	if m == nil {
   257  		return nil, nil
   258  	}
   259  	return swag.WriteJSON(m)
   260  }
   261  
   262  // UnmarshalBinary interface implementation
   263  func (m *WritableVirtualChassis) UnmarshalBinary(b []byte) error {
   264  	var res WritableVirtualChassis
   265  	if err := swag.ReadJSON(b, &res); err != nil {
   266  		return err
   267  	}
   268  	*m = res
   269  	return nil
   270  }