github.com/digitalocean/go-netbox@v0.0.2/netbox/models/inventory_item.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  // InventoryItem inventory item
    34  //
    35  // swagger:model InventoryItem
    36  type InventoryItem struct {
    37  
    38  	// depth
    39  	// Read Only: true
    40  	Depth int64 `json:"_depth,omitempty"`
    41  
    42  	// Asset tag
    43  	//
    44  	// A unique tag used to identify this item
    45  	// Max Length: 50
    46  	AssetTag *string `json:"asset_tag,omitempty"`
    47  
    48  	// Created
    49  	// Read Only: true
    50  	// Format: date
    51  	Created strfmt.Date `json:"created,omitempty"`
    52  
    53  	// Custom fields
    54  	CustomFields interface{} `json:"custom_fields,omitempty"`
    55  
    56  	// Description
    57  	// Max Length: 200
    58  	Description string `json:"description,omitempty"`
    59  
    60  	// device
    61  	// Required: true
    62  	Device *NestedDevice `json:"device"`
    63  
    64  	// Discovered
    65  	//
    66  	// This item was automatically discovered
    67  	Discovered bool `json:"discovered,omitempty"`
    68  
    69  	// Display
    70  	// Read Only: true
    71  	Display string `json:"display,omitempty"`
    72  
    73  	// Id
    74  	// Read Only: true
    75  	ID int64 `json:"id,omitempty"`
    76  
    77  	// Label
    78  	//
    79  	// Physical label
    80  	// Max Length: 64
    81  	Label string `json:"label,omitempty"`
    82  
    83  	// Last updated
    84  	// Read Only: true
    85  	// Format: date-time
    86  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    87  
    88  	// manufacturer
    89  	Manufacturer *NestedManufacturer `json:"manufacturer,omitempty"`
    90  
    91  	// Name
    92  	// Required: true
    93  	// Max Length: 64
    94  	// Min Length: 1
    95  	Name *string `json:"name"`
    96  
    97  	// Parent
    98  	Parent *int64 `json:"parent,omitempty"`
    99  
   100  	// Part ID
   101  	//
   102  	// Manufacturer-assigned part identifier
   103  	// Max Length: 50
   104  	PartID string `json:"part_id,omitempty"`
   105  
   106  	// Serial number
   107  	// Max Length: 50
   108  	Serial string `json:"serial,omitempty"`
   109  
   110  	// tags
   111  	Tags []*NestedTag `json:"tags"`
   112  
   113  	// Url
   114  	// Read Only: true
   115  	// Format: uri
   116  	URL strfmt.URI `json:"url,omitempty"`
   117  }
   118  
   119  // Validate validates this inventory item
   120  func (m *InventoryItem) Validate(formats strfmt.Registry) error {
   121  	var res []error
   122  
   123  	if err := m.validateAssetTag(formats); err != nil {
   124  		res = append(res, err)
   125  	}
   126  
   127  	if err := m.validateCreated(formats); err != nil {
   128  		res = append(res, err)
   129  	}
   130  
   131  	if err := m.validateDescription(formats); err != nil {
   132  		res = append(res, err)
   133  	}
   134  
   135  	if err := m.validateDevice(formats); err != nil {
   136  		res = append(res, err)
   137  	}
   138  
   139  	if err := m.validateLabel(formats); err != nil {
   140  		res = append(res, err)
   141  	}
   142  
   143  	if err := m.validateLastUpdated(formats); err != nil {
   144  		res = append(res, err)
   145  	}
   146  
   147  	if err := m.validateManufacturer(formats); err != nil {
   148  		res = append(res, err)
   149  	}
   150  
   151  	if err := m.validateName(formats); err != nil {
   152  		res = append(res, err)
   153  	}
   154  
   155  	if err := m.validatePartID(formats); err != nil {
   156  		res = append(res, err)
   157  	}
   158  
   159  	if err := m.validateSerial(formats); err != nil {
   160  		res = append(res, err)
   161  	}
   162  
   163  	if err := m.validateTags(formats); err != nil {
   164  		res = append(res, err)
   165  	}
   166  
   167  	if err := m.validateURL(formats); err != nil {
   168  		res = append(res, err)
   169  	}
   170  
   171  	if len(res) > 0 {
   172  		return errors.CompositeValidationError(res...)
   173  	}
   174  	return nil
   175  }
   176  
   177  func (m *InventoryItem) validateAssetTag(formats strfmt.Registry) error {
   178  	if swag.IsZero(m.AssetTag) { // not required
   179  		return nil
   180  	}
   181  
   182  	if err := validate.MaxLength("asset_tag", "body", *m.AssetTag, 50); err != nil {
   183  		return err
   184  	}
   185  
   186  	return nil
   187  }
   188  
   189  func (m *InventoryItem) validateCreated(formats strfmt.Registry) error {
   190  	if swag.IsZero(m.Created) { // not required
   191  		return nil
   192  	}
   193  
   194  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   195  		return err
   196  	}
   197  
   198  	return nil
   199  }
   200  
   201  func (m *InventoryItem) validateDescription(formats strfmt.Registry) error {
   202  	if swag.IsZero(m.Description) { // not required
   203  		return nil
   204  	}
   205  
   206  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   207  		return err
   208  	}
   209  
   210  	return nil
   211  }
   212  
   213  func (m *InventoryItem) validateDevice(formats strfmt.Registry) error {
   214  
   215  	if err := validate.Required("device", "body", m.Device); err != nil {
   216  		return err
   217  	}
   218  
   219  	if m.Device != nil {
   220  		if err := m.Device.Validate(formats); err != nil {
   221  			if ve, ok := err.(*errors.Validation); ok {
   222  				return ve.ValidateName("device")
   223  			} else if ce, ok := err.(*errors.CompositeError); ok {
   224  				return ce.ValidateName("device")
   225  			}
   226  			return err
   227  		}
   228  	}
   229  
   230  	return nil
   231  }
   232  
   233  func (m *InventoryItem) validateLabel(formats strfmt.Registry) error {
   234  	if swag.IsZero(m.Label) { // not required
   235  		return nil
   236  	}
   237  
   238  	if err := validate.MaxLength("label", "body", m.Label, 64); err != nil {
   239  		return err
   240  	}
   241  
   242  	return nil
   243  }
   244  
   245  func (m *InventoryItem) validateLastUpdated(formats strfmt.Registry) error {
   246  	if swag.IsZero(m.LastUpdated) { // not required
   247  		return nil
   248  	}
   249  
   250  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   251  		return err
   252  	}
   253  
   254  	return nil
   255  }
   256  
   257  func (m *InventoryItem) validateManufacturer(formats strfmt.Registry) error {
   258  	if swag.IsZero(m.Manufacturer) { // not required
   259  		return nil
   260  	}
   261  
   262  	if m.Manufacturer != nil {
   263  		if err := m.Manufacturer.Validate(formats); err != nil {
   264  			if ve, ok := err.(*errors.Validation); ok {
   265  				return ve.ValidateName("manufacturer")
   266  			} else if ce, ok := err.(*errors.CompositeError); ok {
   267  				return ce.ValidateName("manufacturer")
   268  			}
   269  			return err
   270  		}
   271  	}
   272  
   273  	return nil
   274  }
   275  
   276  func (m *InventoryItem) validateName(formats strfmt.Registry) error {
   277  
   278  	if err := validate.Required("name", "body", m.Name); err != nil {
   279  		return err
   280  	}
   281  
   282  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   283  		return err
   284  	}
   285  
   286  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   287  		return err
   288  	}
   289  
   290  	return nil
   291  }
   292  
   293  func (m *InventoryItem) validatePartID(formats strfmt.Registry) error {
   294  	if swag.IsZero(m.PartID) { // not required
   295  		return nil
   296  	}
   297  
   298  	if err := validate.MaxLength("part_id", "body", m.PartID, 50); err != nil {
   299  		return err
   300  	}
   301  
   302  	return nil
   303  }
   304  
   305  func (m *InventoryItem) validateSerial(formats strfmt.Registry) error {
   306  	if swag.IsZero(m.Serial) { // not required
   307  		return nil
   308  	}
   309  
   310  	if err := validate.MaxLength("serial", "body", m.Serial, 50); err != nil {
   311  		return err
   312  	}
   313  
   314  	return nil
   315  }
   316  
   317  func (m *InventoryItem) validateTags(formats strfmt.Registry) error {
   318  	if swag.IsZero(m.Tags) { // not required
   319  		return nil
   320  	}
   321  
   322  	for i := 0; i < len(m.Tags); i++ {
   323  		if swag.IsZero(m.Tags[i]) { // not required
   324  			continue
   325  		}
   326  
   327  		if m.Tags[i] != nil {
   328  			if err := m.Tags[i].Validate(formats); err != nil {
   329  				if ve, ok := err.(*errors.Validation); ok {
   330  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   331  				} else if ce, ok := err.(*errors.CompositeError); ok {
   332  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   333  				}
   334  				return err
   335  			}
   336  		}
   337  
   338  	}
   339  
   340  	return nil
   341  }
   342  
   343  func (m *InventoryItem) validateURL(formats strfmt.Registry) error {
   344  	if swag.IsZero(m.URL) { // not required
   345  		return nil
   346  	}
   347  
   348  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   349  		return err
   350  	}
   351  
   352  	return nil
   353  }
   354  
   355  // ContextValidate validate this inventory item based on the context it is used
   356  func (m *InventoryItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   357  	var res []error
   358  
   359  	if err := m.contextValidateDepth(ctx, formats); err != nil {
   360  		res = append(res, err)
   361  	}
   362  
   363  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   364  		res = append(res, err)
   365  	}
   366  
   367  	if err := m.contextValidateDevice(ctx, formats); err != nil {
   368  		res = append(res, err)
   369  	}
   370  
   371  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   372  		res = append(res, err)
   373  	}
   374  
   375  	if err := m.contextValidateID(ctx, formats); err != nil {
   376  		res = append(res, err)
   377  	}
   378  
   379  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   380  		res = append(res, err)
   381  	}
   382  
   383  	if err := m.contextValidateManufacturer(ctx, formats); err != nil {
   384  		res = append(res, err)
   385  	}
   386  
   387  	if err := m.contextValidateTags(ctx, formats); err != nil {
   388  		res = append(res, err)
   389  	}
   390  
   391  	if err := m.contextValidateURL(ctx, formats); err != nil {
   392  		res = append(res, err)
   393  	}
   394  
   395  	if len(res) > 0 {
   396  		return errors.CompositeValidationError(res...)
   397  	}
   398  	return nil
   399  }
   400  
   401  func (m *InventoryItem) contextValidateDepth(ctx context.Context, formats strfmt.Registry) error {
   402  
   403  	if err := validate.ReadOnly(ctx, "_depth", "body", int64(m.Depth)); err != nil {
   404  		return err
   405  	}
   406  
   407  	return nil
   408  }
   409  
   410  func (m *InventoryItem) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   411  
   412  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   413  		return err
   414  	}
   415  
   416  	return nil
   417  }
   418  
   419  func (m *InventoryItem) contextValidateDevice(ctx context.Context, formats strfmt.Registry) error {
   420  
   421  	if m.Device != nil {
   422  		if err := m.Device.ContextValidate(ctx, formats); err != nil {
   423  			if ve, ok := err.(*errors.Validation); ok {
   424  				return ve.ValidateName("device")
   425  			} else if ce, ok := err.(*errors.CompositeError); ok {
   426  				return ce.ValidateName("device")
   427  			}
   428  			return err
   429  		}
   430  	}
   431  
   432  	return nil
   433  }
   434  
   435  func (m *InventoryItem) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   436  
   437  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   438  		return err
   439  	}
   440  
   441  	return nil
   442  }
   443  
   444  func (m *InventoryItem) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   445  
   446  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   447  		return err
   448  	}
   449  
   450  	return nil
   451  }
   452  
   453  func (m *InventoryItem) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   454  
   455  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   456  		return err
   457  	}
   458  
   459  	return nil
   460  }
   461  
   462  func (m *InventoryItem) contextValidateManufacturer(ctx context.Context, formats strfmt.Registry) error {
   463  
   464  	if m.Manufacturer != nil {
   465  		if err := m.Manufacturer.ContextValidate(ctx, formats); err != nil {
   466  			if ve, ok := err.(*errors.Validation); ok {
   467  				return ve.ValidateName("manufacturer")
   468  			} else if ce, ok := err.(*errors.CompositeError); ok {
   469  				return ce.ValidateName("manufacturer")
   470  			}
   471  			return err
   472  		}
   473  	}
   474  
   475  	return nil
   476  }
   477  
   478  func (m *InventoryItem) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   479  
   480  	for i := 0; i < len(m.Tags); i++ {
   481  
   482  		if m.Tags[i] != nil {
   483  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   484  				if ve, ok := err.(*errors.Validation); ok {
   485  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   486  				} else if ce, ok := err.(*errors.CompositeError); ok {
   487  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   488  				}
   489  				return err
   490  			}
   491  		}
   492  
   493  	}
   494  
   495  	return nil
   496  }
   497  
   498  func (m *InventoryItem) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   499  
   500  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   501  		return err
   502  	}
   503  
   504  	return nil
   505  }
   506  
   507  // MarshalBinary interface implementation
   508  func (m *InventoryItem) MarshalBinary() ([]byte, error) {
   509  	if m == nil {
   510  		return nil, nil
   511  	}
   512  	return swag.WriteJSON(m)
   513  }
   514  
   515  // UnmarshalBinary interface implementation
   516  func (m *InventoryItem) UnmarshalBinary(b []byte) error {
   517  	var res InventoryItem
   518  	if err := swag.ReadJSON(b, &res); err != nil {
   519  		return err
   520  	}
   521  	*m = res
   522  	return nil
   523  }