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