github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_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  // WritableInventoryItem writable inventory item
    34  //
    35  // swagger:model WritableInventoryItem
    36  type WritableInventoryItem 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 *int64 `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 *int64 `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 writable inventory item
   120  func (m *WritableInventoryItem) 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.validateName(formats); err != nil {
   148  		res = append(res, err)
   149  	}
   150  
   151  	if err := m.validatePartID(formats); err != nil {
   152  		res = append(res, err)
   153  	}
   154  
   155  	if err := m.validateSerial(formats); err != nil {
   156  		res = append(res, err)
   157  	}
   158  
   159  	if err := m.validateTags(formats); err != nil {
   160  		res = append(res, err)
   161  	}
   162  
   163  	if err := m.validateURL(formats); err != nil {
   164  		res = append(res, err)
   165  	}
   166  
   167  	if len(res) > 0 {
   168  		return errors.CompositeValidationError(res...)
   169  	}
   170  	return nil
   171  }
   172  
   173  func (m *WritableInventoryItem) validateAssetTag(formats strfmt.Registry) error {
   174  	if swag.IsZero(m.AssetTag) { // not required
   175  		return nil
   176  	}
   177  
   178  	if err := validate.MaxLength("asset_tag", "body", *m.AssetTag, 50); err != nil {
   179  		return err
   180  	}
   181  
   182  	return nil
   183  }
   184  
   185  func (m *WritableInventoryItem) validateCreated(formats strfmt.Registry) error {
   186  	if swag.IsZero(m.Created) { // not required
   187  		return nil
   188  	}
   189  
   190  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   191  		return err
   192  	}
   193  
   194  	return nil
   195  }
   196  
   197  func (m *WritableInventoryItem) validateDescription(formats strfmt.Registry) error {
   198  	if swag.IsZero(m.Description) { // not required
   199  		return nil
   200  	}
   201  
   202  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   203  		return err
   204  	}
   205  
   206  	return nil
   207  }
   208  
   209  func (m *WritableInventoryItem) validateDevice(formats strfmt.Registry) error {
   210  
   211  	if err := validate.Required("device", "body", m.Device); err != nil {
   212  		return err
   213  	}
   214  
   215  	return nil
   216  }
   217  
   218  func (m *WritableInventoryItem) validateLabel(formats strfmt.Registry) error {
   219  	if swag.IsZero(m.Label) { // not required
   220  		return nil
   221  	}
   222  
   223  	if err := validate.MaxLength("label", "body", m.Label, 64); err != nil {
   224  		return err
   225  	}
   226  
   227  	return nil
   228  }
   229  
   230  func (m *WritableInventoryItem) validateLastUpdated(formats strfmt.Registry) error {
   231  	if swag.IsZero(m.LastUpdated) { // not required
   232  		return nil
   233  	}
   234  
   235  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   236  		return err
   237  	}
   238  
   239  	return nil
   240  }
   241  
   242  func (m *WritableInventoryItem) validateName(formats strfmt.Registry) error {
   243  
   244  	if err := validate.Required("name", "body", m.Name); err != nil {
   245  		return err
   246  	}
   247  
   248  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   249  		return err
   250  	}
   251  
   252  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   253  		return err
   254  	}
   255  
   256  	return nil
   257  }
   258  
   259  func (m *WritableInventoryItem) validatePartID(formats strfmt.Registry) error {
   260  	if swag.IsZero(m.PartID) { // not required
   261  		return nil
   262  	}
   263  
   264  	if err := validate.MaxLength("part_id", "body", m.PartID, 50); err != nil {
   265  		return err
   266  	}
   267  
   268  	return nil
   269  }
   270  
   271  func (m *WritableInventoryItem) validateSerial(formats strfmt.Registry) error {
   272  	if swag.IsZero(m.Serial) { // not required
   273  		return nil
   274  	}
   275  
   276  	if err := validate.MaxLength("serial", "body", m.Serial, 50); err != nil {
   277  		return err
   278  	}
   279  
   280  	return nil
   281  }
   282  
   283  func (m *WritableInventoryItem) validateTags(formats strfmt.Registry) error {
   284  	if swag.IsZero(m.Tags) { // not required
   285  		return nil
   286  	}
   287  
   288  	for i := 0; i < len(m.Tags); i++ {
   289  		if swag.IsZero(m.Tags[i]) { // not required
   290  			continue
   291  		}
   292  
   293  		if m.Tags[i] != nil {
   294  			if err := m.Tags[i].Validate(formats); err != nil {
   295  				if ve, ok := err.(*errors.Validation); ok {
   296  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   297  				} else if ce, ok := err.(*errors.CompositeError); ok {
   298  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   299  				}
   300  				return err
   301  			}
   302  		}
   303  
   304  	}
   305  
   306  	return nil
   307  }
   308  
   309  func (m *WritableInventoryItem) validateURL(formats strfmt.Registry) error {
   310  	if swag.IsZero(m.URL) { // not required
   311  		return nil
   312  	}
   313  
   314  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   315  		return err
   316  	}
   317  
   318  	return nil
   319  }
   320  
   321  // ContextValidate validate this writable inventory item based on the context it is used
   322  func (m *WritableInventoryItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   323  	var res []error
   324  
   325  	if err := m.contextValidateDepth(ctx, formats); err != nil {
   326  		res = append(res, err)
   327  	}
   328  
   329  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   330  		res = append(res, err)
   331  	}
   332  
   333  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   334  		res = append(res, err)
   335  	}
   336  
   337  	if err := m.contextValidateID(ctx, formats); err != nil {
   338  		res = append(res, err)
   339  	}
   340  
   341  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   342  		res = append(res, err)
   343  	}
   344  
   345  	if err := m.contextValidateTags(ctx, formats); err != nil {
   346  		res = append(res, err)
   347  	}
   348  
   349  	if err := m.contextValidateURL(ctx, formats); err != nil {
   350  		res = append(res, err)
   351  	}
   352  
   353  	if len(res) > 0 {
   354  		return errors.CompositeValidationError(res...)
   355  	}
   356  	return nil
   357  }
   358  
   359  func (m *WritableInventoryItem) contextValidateDepth(ctx context.Context, formats strfmt.Registry) error {
   360  
   361  	if err := validate.ReadOnly(ctx, "_depth", "body", int64(m.Depth)); err != nil {
   362  		return err
   363  	}
   364  
   365  	return nil
   366  }
   367  
   368  func (m *WritableInventoryItem) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   369  
   370  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   371  		return err
   372  	}
   373  
   374  	return nil
   375  }
   376  
   377  func (m *WritableInventoryItem) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   378  
   379  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   380  		return err
   381  	}
   382  
   383  	return nil
   384  }
   385  
   386  func (m *WritableInventoryItem) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   387  
   388  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   389  		return err
   390  	}
   391  
   392  	return nil
   393  }
   394  
   395  func (m *WritableInventoryItem) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   396  
   397  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   398  		return err
   399  	}
   400  
   401  	return nil
   402  }
   403  
   404  func (m *WritableInventoryItem) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   405  
   406  	for i := 0; i < len(m.Tags); i++ {
   407  
   408  		if m.Tags[i] != nil {
   409  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   410  				if ve, ok := err.(*errors.Validation); ok {
   411  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   412  				} else if ce, ok := err.(*errors.CompositeError); ok {
   413  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   414  				}
   415  				return err
   416  			}
   417  		}
   418  
   419  	}
   420  
   421  	return nil
   422  }
   423  
   424  func (m *WritableInventoryItem) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   425  
   426  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   427  		return err
   428  	}
   429  
   430  	return nil
   431  }
   432  
   433  // MarshalBinary interface implementation
   434  func (m *WritableInventoryItem) MarshalBinary() ([]byte, error) {
   435  	if m == nil {
   436  		return nil, nil
   437  	}
   438  	return swag.WriteJSON(m)
   439  }
   440  
   441  // UnmarshalBinary interface implementation
   442  func (m *WritableInventoryItem) UnmarshalBinary(b []byte) error {
   443  	var res WritableInventoryItem
   444  	if err := swag.ReadJSON(b, &res); err != nil {
   445  		return err
   446  	}
   447  	*m = res
   448  	return nil
   449  }