github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_device_bay.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  // WritableDeviceBay writable device bay
    34  //
    35  // swagger:model WritableDeviceBay
    36  type WritableDeviceBay struct {
    37  
    38  	// Created
    39  	// Read Only: true
    40  	// Format: date
    41  	Created strfmt.Date `json:"created,omitempty"`
    42  
    43  	// Custom fields
    44  	CustomFields interface{} `json:"custom_fields,omitempty"`
    45  
    46  	// Description
    47  	// Max Length: 200
    48  	Description string `json:"description,omitempty"`
    49  
    50  	// Device
    51  	// Required: true
    52  	Device *int64 `json:"device"`
    53  
    54  	// Display
    55  	// Read Only: true
    56  	Display string `json:"display,omitempty"`
    57  
    58  	// Id
    59  	// Read Only: true
    60  	ID int64 `json:"id,omitempty"`
    61  
    62  	// Installed device
    63  	InstalledDevice *int64 `json:"installed_device,omitempty"`
    64  
    65  	// Label
    66  	//
    67  	// Physical label
    68  	// Max Length: 64
    69  	Label string `json:"label,omitempty"`
    70  
    71  	// Last updated
    72  	// Read Only: true
    73  	// Format: date-time
    74  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    75  
    76  	// Name
    77  	// Required: true
    78  	// Max Length: 64
    79  	// Min Length: 1
    80  	Name *string `json:"name"`
    81  
    82  	// tags
    83  	Tags []*NestedTag `json:"tags"`
    84  
    85  	// Url
    86  	// Read Only: true
    87  	// Format: uri
    88  	URL strfmt.URI `json:"url,omitempty"`
    89  }
    90  
    91  // Validate validates this writable device bay
    92  func (m *WritableDeviceBay) Validate(formats strfmt.Registry) error {
    93  	var res []error
    94  
    95  	if err := m.validateCreated(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if err := m.validateDescription(formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := m.validateDevice(formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if err := m.validateLabel(formats); err != nil {
   108  		res = append(res, err)
   109  	}
   110  
   111  	if err := m.validateLastUpdated(formats); err != nil {
   112  		res = append(res, err)
   113  	}
   114  
   115  	if err := m.validateName(formats); err != nil {
   116  		res = append(res, err)
   117  	}
   118  
   119  	if err := m.validateTags(formats); err != nil {
   120  		res = append(res, err)
   121  	}
   122  
   123  	if err := m.validateURL(formats); err != nil {
   124  		res = append(res, err)
   125  	}
   126  
   127  	if len(res) > 0 {
   128  		return errors.CompositeValidationError(res...)
   129  	}
   130  	return nil
   131  }
   132  
   133  func (m *WritableDeviceBay) validateCreated(formats strfmt.Registry) error {
   134  	if swag.IsZero(m.Created) { // not required
   135  		return nil
   136  	}
   137  
   138  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   139  		return err
   140  	}
   141  
   142  	return nil
   143  }
   144  
   145  func (m *WritableDeviceBay) validateDescription(formats strfmt.Registry) error {
   146  	if swag.IsZero(m.Description) { // not required
   147  		return nil
   148  	}
   149  
   150  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   151  		return err
   152  	}
   153  
   154  	return nil
   155  }
   156  
   157  func (m *WritableDeviceBay) validateDevice(formats strfmt.Registry) error {
   158  
   159  	if err := validate.Required("device", "body", m.Device); err != nil {
   160  		return err
   161  	}
   162  
   163  	return nil
   164  }
   165  
   166  func (m *WritableDeviceBay) validateLabel(formats strfmt.Registry) error {
   167  	if swag.IsZero(m.Label) { // not required
   168  		return nil
   169  	}
   170  
   171  	if err := validate.MaxLength("label", "body", m.Label, 64); err != nil {
   172  		return err
   173  	}
   174  
   175  	return nil
   176  }
   177  
   178  func (m *WritableDeviceBay) validateLastUpdated(formats strfmt.Registry) error {
   179  	if swag.IsZero(m.LastUpdated) { // not required
   180  		return nil
   181  	}
   182  
   183  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   184  		return err
   185  	}
   186  
   187  	return nil
   188  }
   189  
   190  func (m *WritableDeviceBay) validateName(formats strfmt.Registry) error {
   191  
   192  	if err := validate.Required("name", "body", m.Name); err != nil {
   193  		return err
   194  	}
   195  
   196  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   197  		return err
   198  	}
   199  
   200  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   201  		return err
   202  	}
   203  
   204  	return nil
   205  }
   206  
   207  func (m *WritableDeviceBay) validateTags(formats strfmt.Registry) error {
   208  	if swag.IsZero(m.Tags) { // not required
   209  		return nil
   210  	}
   211  
   212  	for i := 0; i < len(m.Tags); i++ {
   213  		if swag.IsZero(m.Tags[i]) { // not required
   214  			continue
   215  		}
   216  
   217  		if m.Tags[i] != nil {
   218  			if err := m.Tags[i].Validate(formats); err != nil {
   219  				if ve, ok := err.(*errors.Validation); ok {
   220  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   221  				} else if ce, ok := err.(*errors.CompositeError); ok {
   222  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   223  				}
   224  				return err
   225  			}
   226  		}
   227  
   228  	}
   229  
   230  	return nil
   231  }
   232  
   233  func (m *WritableDeviceBay) validateURL(formats strfmt.Registry) error {
   234  	if swag.IsZero(m.URL) { // not required
   235  		return nil
   236  	}
   237  
   238  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   239  		return err
   240  	}
   241  
   242  	return nil
   243  }
   244  
   245  // ContextValidate validate this writable device bay based on the context it is used
   246  func (m *WritableDeviceBay) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   247  	var res []error
   248  
   249  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   250  		res = append(res, err)
   251  	}
   252  
   253  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   254  		res = append(res, err)
   255  	}
   256  
   257  	if err := m.contextValidateID(ctx, formats); err != nil {
   258  		res = append(res, err)
   259  	}
   260  
   261  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   262  		res = append(res, err)
   263  	}
   264  
   265  	if err := m.contextValidateTags(ctx, formats); err != nil {
   266  		res = append(res, err)
   267  	}
   268  
   269  	if err := m.contextValidateURL(ctx, formats); err != nil {
   270  		res = append(res, err)
   271  	}
   272  
   273  	if len(res) > 0 {
   274  		return errors.CompositeValidationError(res...)
   275  	}
   276  	return nil
   277  }
   278  
   279  func (m *WritableDeviceBay) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   280  
   281  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   282  		return err
   283  	}
   284  
   285  	return nil
   286  }
   287  
   288  func (m *WritableDeviceBay) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   289  
   290  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   291  		return err
   292  	}
   293  
   294  	return nil
   295  }
   296  
   297  func (m *WritableDeviceBay) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   298  
   299  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   300  		return err
   301  	}
   302  
   303  	return nil
   304  }
   305  
   306  func (m *WritableDeviceBay) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   307  
   308  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   309  		return err
   310  	}
   311  
   312  	return nil
   313  }
   314  
   315  func (m *WritableDeviceBay) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   316  
   317  	for i := 0; i < len(m.Tags); i++ {
   318  
   319  		if m.Tags[i] != nil {
   320  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   321  				if ve, ok := err.(*errors.Validation); ok {
   322  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   323  				} else if ce, ok := err.(*errors.CompositeError); ok {
   324  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   325  				}
   326  				return err
   327  			}
   328  		}
   329  
   330  	}
   331  
   332  	return nil
   333  }
   334  
   335  func (m *WritableDeviceBay) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   336  
   337  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   338  		return err
   339  	}
   340  
   341  	return nil
   342  }
   343  
   344  // MarshalBinary interface implementation
   345  func (m *WritableDeviceBay) MarshalBinary() ([]byte, error) {
   346  	if m == nil {
   347  		return nil, nil
   348  	}
   349  	return swag.WriteJSON(m)
   350  }
   351  
   352  // UnmarshalBinary interface implementation
   353  func (m *WritableDeviceBay) UnmarshalBinary(b []byte) error {
   354  	var res WritableDeviceBay
   355  	if err := swag.ReadJSON(b, &res); err != nil {
   356  		return err
   357  	}
   358  	*m = res
   359  	return nil
   360  }