github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_console_port.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  	"encoding/json"
    26  	"strconv"
    27  
    28  	"github.com/go-openapi/errors"
    29  	"github.com/go-openapi/strfmt"
    30  	"github.com/go-openapi/swag"
    31  	"github.com/go-openapi/validate"
    32  )
    33  
    34  // WritableConsolePort writable console port
    35  //
    36  // swagger:model WritableConsolePort
    37  type WritableConsolePort struct {
    38  
    39  	// occupied
    40  	// Read Only: true
    41  	Occupied *bool `json:"_occupied,omitempty"`
    42  
    43  	// cable
    44  	Cable *NestedCable `json:"cable,omitempty"`
    45  
    46  	// Cable peer
    47  	//
    48  	//
    49  	// Return the appropriate serializer for the cable termination model.
    50  	//
    51  	// Read Only: true
    52  	CablePeer map[string]*string `json:"cable_peer,omitempty"`
    53  
    54  	// Cable peer type
    55  	// Read Only: true
    56  	CablePeerType string `json:"cable_peer_type,omitempty"`
    57  
    58  	// Connected endpoint
    59  	//
    60  	//
    61  	// Return the appropriate serializer for the type of connected object.
    62  	//
    63  	// Read Only: true
    64  	ConnectedEndpoint map[string]*string `json:"connected_endpoint,omitempty"`
    65  
    66  	// Connected endpoint reachable
    67  	// Read Only: true
    68  	ConnectedEndpointReachable *bool `json:"connected_endpoint_reachable,omitempty"`
    69  
    70  	// Connected endpoint type
    71  	// Read Only: true
    72  	ConnectedEndpointType string `json:"connected_endpoint_type,omitempty"`
    73  
    74  	// Created
    75  	// Read Only: true
    76  	// Format: date
    77  	Created strfmt.Date `json:"created,omitempty"`
    78  
    79  	// Custom fields
    80  	CustomFields interface{} `json:"custom_fields,omitempty"`
    81  
    82  	// Description
    83  	// Max Length: 200
    84  	Description string `json:"description,omitempty"`
    85  
    86  	// Device
    87  	// Required: true
    88  	Device *int64 `json:"device"`
    89  
    90  	// Display
    91  	// Read Only: true
    92  	Display string `json:"display,omitempty"`
    93  
    94  	// Id
    95  	// Read Only: true
    96  	ID int64 `json:"id,omitempty"`
    97  
    98  	// Label
    99  	//
   100  	// Physical label
   101  	// Max Length: 64
   102  	Label string `json:"label,omitempty"`
   103  
   104  	// Last updated
   105  	// Read Only: true
   106  	// Format: date-time
   107  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
   108  
   109  	// Mark connected
   110  	//
   111  	// Treat as if a cable is connected
   112  	MarkConnected bool `json:"mark_connected,omitempty"`
   113  
   114  	// Name
   115  	// Required: true
   116  	// Max Length: 64
   117  	// Min Length: 1
   118  	Name *string `json:"name"`
   119  
   120  	// Speed
   121  	//
   122  	// Port speed in bits per second
   123  	// Enum: [1200 2400 4800 9600 19200 38400 57600 115200]
   124  	Speed *int64 `json:"speed,omitempty"`
   125  
   126  	// tags
   127  	Tags []*NestedTag `json:"tags"`
   128  
   129  	// Type
   130  	//
   131  	// Physical port type
   132  	// Enum: [de-9 db-25 rj-11 rj-12 rj-45 usb-a usb-b usb-c usb-mini-a usb-mini-b usb-micro-a usb-micro-b other]
   133  	Type string `json:"type,omitempty"`
   134  
   135  	// Url
   136  	// Read Only: true
   137  	// Format: uri
   138  	URL strfmt.URI `json:"url,omitempty"`
   139  }
   140  
   141  // Validate validates this writable console port
   142  func (m *WritableConsolePort) Validate(formats strfmt.Registry) error {
   143  	var res []error
   144  
   145  	if err := m.validateCable(formats); err != nil {
   146  		res = append(res, err)
   147  	}
   148  
   149  	if err := m.validateCreated(formats); err != nil {
   150  		res = append(res, err)
   151  	}
   152  
   153  	if err := m.validateDescription(formats); err != nil {
   154  		res = append(res, err)
   155  	}
   156  
   157  	if err := m.validateDevice(formats); err != nil {
   158  		res = append(res, err)
   159  	}
   160  
   161  	if err := m.validateLabel(formats); err != nil {
   162  		res = append(res, err)
   163  	}
   164  
   165  	if err := m.validateLastUpdated(formats); err != nil {
   166  		res = append(res, err)
   167  	}
   168  
   169  	if err := m.validateName(formats); err != nil {
   170  		res = append(res, err)
   171  	}
   172  
   173  	if err := m.validateSpeed(formats); err != nil {
   174  		res = append(res, err)
   175  	}
   176  
   177  	if err := m.validateTags(formats); err != nil {
   178  		res = append(res, err)
   179  	}
   180  
   181  	if err := m.validateType(formats); err != nil {
   182  		res = append(res, err)
   183  	}
   184  
   185  	if err := m.validateURL(formats); err != nil {
   186  		res = append(res, err)
   187  	}
   188  
   189  	if len(res) > 0 {
   190  		return errors.CompositeValidationError(res...)
   191  	}
   192  	return nil
   193  }
   194  
   195  func (m *WritableConsolePort) validateCable(formats strfmt.Registry) error {
   196  	if swag.IsZero(m.Cable) { // not required
   197  		return nil
   198  	}
   199  
   200  	if m.Cable != nil {
   201  		if err := m.Cable.Validate(formats); err != nil {
   202  			if ve, ok := err.(*errors.Validation); ok {
   203  				return ve.ValidateName("cable")
   204  			} else if ce, ok := err.(*errors.CompositeError); ok {
   205  				return ce.ValidateName("cable")
   206  			}
   207  			return err
   208  		}
   209  	}
   210  
   211  	return nil
   212  }
   213  
   214  func (m *WritableConsolePort) validateCreated(formats strfmt.Registry) error {
   215  	if swag.IsZero(m.Created) { // not required
   216  		return nil
   217  	}
   218  
   219  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   220  		return err
   221  	}
   222  
   223  	return nil
   224  }
   225  
   226  func (m *WritableConsolePort) validateDescription(formats strfmt.Registry) error {
   227  	if swag.IsZero(m.Description) { // not required
   228  		return nil
   229  	}
   230  
   231  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   232  		return err
   233  	}
   234  
   235  	return nil
   236  }
   237  
   238  func (m *WritableConsolePort) validateDevice(formats strfmt.Registry) error {
   239  
   240  	if err := validate.Required("device", "body", m.Device); err != nil {
   241  		return err
   242  	}
   243  
   244  	return nil
   245  }
   246  
   247  func (m *WritableConsolePort) validateLabel(formats strfmt.Registry) error {
   248  	if swag.IsZero(m.Label) { // not required
   249  		return nil
   250  	}
   251  
   252  	if err := validate.MaxLength("label", "body", m.Label, 64); err != nil {
   253  		return err
   254  	}
   255  
   256  	return nil
   257  }
   258  
   259  func (m *WritableConsolePort) validateLastUpdated(formats strfmt.Registry) error {
   260  	if swag.IsZero(m.LastUpdated) { // not required
   261  		return nil
   262  	}
   263  
   264  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   265  		return err
   266  	}
   267  
   268  	return nil
   269  }
   270  
   271  func (m *WritableConsolePort) validateName(formats strfmt.Registry) error {
   272  
   273  	if err := validate.Required("name", "body", m.Name); err != nil {
   274  		return err
   275  	}
   276  
   277  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   278  		return err
   279  	}
   280  
   281  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   282  		return err
   283  	}
   284  
   285  	return nil
   286  }
   287  
   288  var writableConsolePortTypeSpeedPropEnum []interface{}
   289  
   290  func init() {
   291  	var res []int64
   292  	if err := json.Unmarshal([]byte(`[1200,2400,4800,9600,19200,38400,57600,115200]`), &res); err != nil {
   293  		panic(err)
   294  	}
   295  	for _, v := range res {
   296  		writableConsolePortTypeSpeedPropEnum = append(writableConsolePortTypeSpeedPropEnum, v)
   297  	}
   298  }
   299  
   300  // prop value enum
   301  func (m *WritableConsolePort) validateSpeedEnum(path, location string, value int64) error {
   302  	if err := validate.EnumCase(path, location, value, writableConsolePortTypeSpeedPropEnum, true); err != nil {
   303  		return err
   304  	}
   305  	return nil
   306  }
   307  
   308  func (m *WritableConsolePort) validateSpeed(formats strfmt.Registry) error {
   309  	if swag.IsZero(m.Speed) { // not required
   310  		return nil
   311  	}
   312  
   313  	// value enum
   314  	if err := m.validateSpeedEnum("speed", "body", *m.Speed); err != nil {
   315  		return err
   316  	}
   317  
   318  	return nil
   319  }
   320  
   321  func (m *WritableConsolePort) validateTags(formats strfmt.Registry) error {
   322  	if swag.IsZero(m.Tags) { // not required
   323  		return nil
   324  	}
   325  
   326  	for i := 0; i < len(m.Tags); i++ {
   327  		if swag.IsZero(m.Tags[i]) { // not required
   328  			continue
   329  		}
   330  
   331  		if m.Tags[i] != nil {
   332  			if err := m.Tags[i].Validate(formats); err != nil {
   333  				if ve, ok := err.(*errors.Validation); ok {
   334  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   335  				} else if ce, ok := err.(*errors.CompositeError); ok {
   336  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   337  				}
   338  				return err
   339  			}
   340  		}
   341  
   342  	}
   343  
   344  	return nil
   345  }
   346  
   347  var writableConsolePortTypeTypePropEnum []interface{}
   348  
   349  func init() {
   350  	var res []string
   351  	if err := json.Unmarshal([]byte(`["de-9","db-25","rj-11","rj-12","rj-45","usb-a","usb-b","usb-c","usb-mini-a","usb-mini-b","usb-micro-a","usb-micro-b","other"]`), &res); err != nil {
   352  		panic(err)
   353  	}
   354  	for _, v := range res {
   355  		writableConsolePortTypeTypePropEnum = append(writableConsolePortTypeTypePropEnum, v)
   356  	}
   357  }
   358  
   359  const (
   360  
   361  	// WritableConsolePortTypeDeDash9 captures enum value "de-9"
   362  	WritableConsolePortTypeDeDash9 string = "de-9"
   363  
   364  	// WritableConsolePortTypeDbDash25 captures enum value "db-25"
   365  	WritableConsolePortTypeDbDash25 string = "db-25"
   366  
   367  	// WritableConsolePortTypeRjDash11 captures enum value "rj-11"
   368  	WritableConsolePortTypeRjDash11 string = "rj-11"
   369  
   370  	// WritableConsolePortTypeRjDash12 captures enum value "rj-12"
   371  	WritableConsolePortTypeRjDash12 string = "rj-12"
   372  
   373  	// WritableConsolePortTypeRjDash45 captures enum value "rj-45"
   374  	WritableConsolePortTypeRjDash45 string = "rj-45"
   375  
   376  	// WritableConsolePortTypeUsbDasha captures enum value "usb-a"
   377  	WritableConsolePortTypeUsbDasha string = "usb-a"
   378  
   379  	// WritableConsolePortTypeUsbDashb captures enum value "usb-b"
   380  	WritableConsolePortTypeUsbDashb string = "usb-b"
   381  
   382  	// WritableConsolePortTypeUsbDashc captures enum value "usb-c"
   383  	WritableConsolePortTypeUsbDashc string = "usb-c"
   384  
   385  	// WritableConsolePortTypeUsbDashMiniDasha captures enum value "usb-mini-a"
   386  	WritableConsolePortTypeUsbDashMiniDasha string = "usb-mini-a"
   387  
   388  	// WritableConsolePortTypeUsbDashMiniDashb captures enum value "usb-mini-b"
   389  	WritableConsolePortTypeUsbDashMiniDashb string = "usb-mini-b"
   390  
   391  	// WritableConsolePortTypeUsbDashMicroDasha captures enum value "usb-micro-a"
   392  	WritableConsolePortTypeUsbDashMicroDasha string = "usb-micro-a"
   393  
   394  	// WritableConsolePortTypeUsbDashMicroDashb captures enum value "usb-micro-b"
   395  	WritableConsolePortTypeUsbDashMicroDashb string = "usb-micro-b"
   396  
   397  	// WritableConsolePortTypeOther captures enum value "other"
   398  	WritableConsolePortTypeOther string = "other"
   399  )
   400  
   401  // prop value enum
   402  func (m *WritableConsolePort) validateTypeEnum(path, location string, value string) error {
   403  	if err := validate.EnumCase(path, location, value, writableConsolePortTypeTypePropEnum, true); err != nil {
   404  		return err
   405  	}
   406  	return nil
   407  }
   408  
   409  func (m *WritableConsolePort) validateType(formats strfmt.Registry) error {
   410  	if swag.IsZero(m.Type) { // not required
   411  		return nil
   412  	}
   413  
   414  	// value enum
   415  	if err := m.validateTypeEnum("type", "body", m.Type); err != nil {
   416  		return err
   417  	}
   418  
   419  	return nil
   420  }
   421  
   422  func (m *WritableConsolePort) validateURL(formats strfmt.Registry) error {
   423  	if swag.IsZero(m.URL) { // not required
   424  		return nil
   425  	}
   426  
   427  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   428  		return err
   429  	}
   430  
   431  	return nil
   432  }
   433  
   434  // ContextValidate validate this writable console port based on the context it is used
   435  func (m *WritableConsolePort) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   436  	var res []error
   437  
   438  	if err := m.contextValidateOccupied(ctx, formats); err != nil {
   439  		res = append(res, err)
   440  	}
   441  
   442  	if err := m.contextValidateCable(ctx, formats); err != nil {
   443  		res = append(res, err)
   444  	}
   445  
   446  	if err := m.contextValidateCablePeer(ctx, formats); err != nil {
   447  		res = append(res, err)
   448  	}
   449  
   450  	if err := m.contextValidateCablePeerType(ctx, formats); err != nil {
   451  		res = append(res, err)
   452  	}
   453  
   454  	if err := m.contextValidateConnectedEndpoint(ctx, formats); err != nil {
   455  		res = append(res, err)
   456  	}
   457  
   458  	if err := m.contextValidateConnectedEndpointReachable(ctx, formats); err != nil {
   459  		res = append(res, err)
   460  	}
   461  
   462  	if err := m.contextValidateConnectedEndpointType(ctx, formats); err != nil {
   463  		res = append(res, err)
   464  	}
   465  
   466  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   467  		res = append(res, err)
   468  	}
   469  
   470  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   471  		res = append(res, err)
   472  	}
   473  
   474  	if err := m.contextValidateID(ctx, formats); err != nil {
   475  		res = append(res, err)
   476  	}
   477  
   478  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   479  		res = append(res, err)
   480  	}
   481  
   482  	if err := m.contextValidateTags(ctx, formats); err != nil {
   483  		res = append(res, err)
   484  	}
   485  
   486  	if err := m.contextValidateURL(ctx, formats); err != nil {
   487  		res = append(res, err)
   488  	}
   489  
   490  	if len(res) > 0 {
   491  		return errors.CompositeValidationError(res...)
   492  	}
   493  	return nil
   494  }
   495  
   496  func (m *WritableConsolePort) contextValidateOccupied(ctx context.Context, formats strfmt.Registry) error {
   497  
   498  	if err := validate.ReadOnly(ctx, "_occupied", "body", m.Occupied); err != nil {
   499  		return err
   500  	}
   501  
   502  	return nil
   503  }
   504  
   505  func (m *WritableConsolePort) contextValidateCable(ctx context.Context, formats strfmt.Registry) error {
   506  
   507  	if m.Cable != nil {
   508  		if err := m.Cable.ContextValidate(ctx, formats); err != nil {
   509  			if ve, ok := err.(*errors.Validation); ok {
   510  				return ve.ValidateName("cable")
   511  			} else if ce, ok := err.(*errors.CompositeError); ok {
   512  				return ce.ValidateName("cable")
   513  			}
   514  			return err
   515  		}
   516  	}
   517  
   518  	return nil
   519  }
   520  
   521  func (m *WritableConsolePort) contextValidateCablePeer(ctx context.Context, formats strfmt.Registry) error {
   522  
   523  	return nil
   524  }
   525  
   526  func (m *WritableConsolePort) contextValidateCablePeerType(ctx context.Context, formats strfmt.Registry) error {
   527  
   528  	if err := validate.ReadOnly(ctx, "cable_peer_type", "body", string(m.CablePeerType)); err != nil {
   529  		return err
   530  	}
   531  
   532  	return nil
   533  }
   534  
   535  func (m *WritableConsolePort) contextValidateConnectedEndpoint(ctx context.Context, formats strfmt.Registry) error {
   536  
   537  	return nil
   538  }
   539  
   540  func (m *WritableConsolePort) contextValidateConnectedEndpointReachable(ctx context.Context, formats strfmt.Registry) error {
   541  
   542  	if err := validate.ReadOnly(ctx, "connected_endpoint_reachable", "body", m.ConnectedEndpointReachable); err != nil {
   543  		return err
   544  	}
   545  
   546  	return nil
   547  }
   548  
   549  func (m *WritableConsolePort) contextValidateConnectedEndpointType(ctx context.Context, formats strfmt.Registry) error {
   550  
   551  	if err := validate.ReadOnly(ctx, "connected_endpoint_type", "body", string(m.ConnectedEndpointType)); err != nil {
   552  		return err
   553  	}
   554  
   555  	return nil
   556  }
   557  
   558  func (m *WritableConsolePort) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   559  
   560  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   561  		return err
   562  	}
   563  
   564  	return nil
   565  }
   566  
   567  func (m *WritableConsolePort) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   568  
   569  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   570  		return err
   571  	}
   572  
   573  	return nil
   574  }
   575  
   576  func (m *WritableConsolePort) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   577  
   578  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   579  		return err
   580  	}
   581  
   582  	return nil
   583  }
   584  
   585  func (m *WritableConsolePort) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   586  
   587  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   588  		return err
   589  	}
   590  
   591  	return nil
   592  }
   593  
   594  func (m *WritableConsolePort) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   595  
   596  	for i := 0; i < len(m.Tags); i++ {
   597  
   598  		if m.Tags[i] != nil {
   599  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   600  				if ve, ok := err.(*errors.Validation); ok {
   601  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   602  				} else if ce, ok := err.(*errors.CompositeError); ok {
   603  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   604  				}
   605  				return err
   606  			}
   607  		}
   608  
   609  	}
   610  
   611  	return nil
   612  }
   613  
   614  func (m *WritableConsolePort) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   615  
   616  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   617  		return err
   618  	}
   619  
   620  	return nil
   621  }
   622  
   623  // MarshalBinary interface implementation
   624  func (m *WritableConsolePort) MarshalBinary() ([]byte, error) {
   625  	if m == nil {
   626  		return nil, nil
   627  	}
   628  	return swag.WriteJSON(m)
   629  }
   630  
   631  // UnmarshalBinary interface implementation
   632  func (m *WritableConsolePort) UnmarshalBinary(b []byte) error {
   633  	var res WritableConsolePort
   634  	if err := swag.ReadJSON(b, &res); err != nil {
   635  		return err
   636  	}
   637  	*m = res
   638  	return nil
   639  }