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