github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_provider_network.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  // WritableProviderNetwork writable provider network
    34  //
    35  // swagger:model WritableProviderNetwork
    36  type WritableProviderNetwork struct {
    37  
    38  	// Comments
    39  	Comments string `json:"comments,omitempty"`
    40  
    41  	// Created
    42  	// Read Only: true
    43  	// Format: date
    44  	Created strfmt.Date `json:"created,omitempty"`
    45  
    46  	// Custom fields
    47  	CustomFields interface{} `json:"custom_fields,omitempty"`
    48  
    49  	// Description
    50  	// Max Length: 200
    51  	Description string `json:"description,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  	// Name
    67  	// Required: true
    68  	// Max Length: 100
    69  	// Min Length: 1
    70  	Name *string `json:"name"`
    71  
    72  	// Provider
    73  	// Required: true
    74  	Provider *int64 `json:"provider"`
    75  
    76  	// tags
    77  	Tags []*NestedTag `json:"tags"`
    78  
    79  	// Url
    80  	// Read Only: true
    81  	// Format: uri
    82  	URL strfmt.URI `json:"url,omitempty"`
    83  }
    84  
    85  // Validate validates this writable provider network
    86  func (m *WritableProviderNetwork) Validate(formats strfmt.Registry) error {
    87  	var res []error
    88  
    89  	if err := m.validateCreated(formats); err != nil {
    90  		res = append(res, err)
    91  	}
    92  
    93  	if err := m.validateDescription(formats); err != nil {
    94  		res = append(res, err)
    95  	}
    96  
    97  	if err := m.validateLastUpdated(formats); err != nil {
    98  		res = append(res, err)
    99  	}
   100  
   101  	if err := m.validateName(formats); err != nil {
   102  		res = append(res, err)
   103  	}
   104  
   105  	if err := m.validateProvider(formats); err != nil {
   106  		res = append(res, err)
   107  	}
   108  
   109  	if err := m.validateTags(formats); err != nil {
   110  		res = append(res, err)
   111  	}
   112  
   113  	if err := m.validateURL(formats); err != nil {
   114  		res = append(res, err)
   115  	}
   116  
   117  	if len(res) > 0 {
   118  		return errors.CompositeValidationError(res...)
   119  	}
   120  	return nil
   121  }
   122  
   123  func (m *WritableProviderNetwork) validateCreated(formats strfmt.Registry) error {
   124  	if swag.IsZero(m.Created) { // not required
   125  		return nil
   126  	}
   127  
   128  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   129  		return err
   130  	}
   131  
   132  	return nil
   133  }
   134  
   135  func (m *WritableProviderNetwork) validateDescription(formats strfmt.Registry) error {
   136  	if swag.IsZero(m.Description) { // not required
   137  		return nil
   138  	}
   139  
   140  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   141  		return err
   142  	}
   143  
   144  	return nil
   145  }
   146  
   147  func (m *WritableProviderNetwork) validateLastUpdated(formats strfmt.Registry) error {
   148  	if swag.IsZero(m.LastUpdated) { // not required
   149  		return nil
   150  	}
   151  
   152  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   153  		return err
   154  	}
   155  
   156  	return nil
   157  }
   158  
   159  func (m *WritableProviderNetwork) validateName(formats strfmt.Registry) error {
   160  
   161  	if err := validate.Required("name", "body", m.Name); err != nil {
   162  		return err
   163  	}
   164  
   165  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   166  		return err
   167  	}
   168  
   169  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   170  		return err
   171  	}
   172  
   173  	return nil
   174  }
   175  
   176  func (m *WritableProviderNetwork) validateProvider(formats strfmt.Registry) error {
   177  
   178  	if err := validate.Required("provider", "body", m.Provider); err != nil {
   179  		return err
   180  	}
   181  
   182  	return nil
   183  }
   184  
   185  func (m *WritableProviderNetwork) validateTags(formats strfmt.Registry) error {
   186  	if swag.IsZero(m.Tags) { // not required
   187  		return nil
   188  	}
   189  
   190  	for i := 0; i < len(m.Tags); i++ {
   191  		if swag.IsZero(m.Tags[i]) { // not required
   192  			continue
   193  		}
   194  
   195  		if m.Tags[i] != nil {
   196  			if err := m.Tags[i].Validate(formats); err != nil {
   197  				if ve, ok := err.(*errors.Validation); ok {
   198  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   199  				} else if ce, ok := err.(*errors.CompositeError); ok {
   200  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   201  				}
   202  				return err
   203  			}
   204  		}
   205  
   206  	}
   207  
   208  	return nil
   209  }
   210  
   211  func (m *WritableProviderNetwork) validateURL(formats strfmt.Registry) error {
   212  	if swag.IsZero(m.URL) { // not required
   213  		return nil
   214  	}
   215  
   216  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   217  		return err
   218  	}
   219  
   220  	return nil
   221  }
   222  
   223  // ContextValidate validate this writable provider network based on the context it is used
   224  func (m *WritableProviderNetwork) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   225  	var res []error
   226  
   227  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   228  		res = append(res, err)
   229  	}
   230  
   231  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   232  		res = append(res, err)
   233  	}
   234  
   235  	if err := m.contextValidateID(ctx, formats); err != nil {
   236  		res = append(res, err)
   237  	}
   238  
   239  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   240  		res = append(res, err)
   241  	}
   242  
   243  	if err := m.contextValidateTags(ctx, formats); err != nil {
   244  		res = append(res, err)
   245  	}
   246  
   247  	if err := m.contextValidateURL(ctx, formats); err != nil {
   248  		res = append(res, err)
   249  	}
   250  
   251  	if len(res) > 0 {
   252  		return errors.CompositeValidationError(res...)
   253  	}
   254  	return nil
   255  }
   256  
   257  func (m *WritableProviderNetwork) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   258  
   259  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   260  		return err
   261  	}
   262  
   263  	return nil
   264  }
   265  
   266  func (m *WritableProviderNetwork) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   267  
   268  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   269  		return err
   270  	}
   271  
   272  	return nil
   273  }
   274  
   275  func (m *WritableProviderNetwork) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   276  
   277  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   278  		return err
   279  	}
   280  
   281  	return nil
   282  }
   283  
   284  func (m *WritableProviderNetwork) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   285  
   286  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   287  		return err
   288  	}
   289  
   290  	return nil
   291  }
   292  
   293  func (m *WritableProviderNetwork) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   294  
   295  	for i := 0; i < len(m.Tags); i++ {
   296  
   297  		if m.Tags[i] != nil {
   298  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   299  				if ve, ok := err.(*errors.Validation); ok {
   300  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   301  				} else if ce, ok := err.(*errors.CompositeError); ok {
   302  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   303  				}
   304  				return err
   305  			}
   306  		}
   307  
   308  	}
   309  
   310  	return nil
   311  }
   312  
   313  func (m *WritableProviderNetwork) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   314  
   315  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   316  		return err
   317  	}
   318  
   319  	return nil
   320  }
   321  
   322  // MarshalBinary interface implementation
   323  func (m *WritableProviderNetwork) MarshalBinary() ([]byte, error) {
   324  	if m == nil {
   325  		return nil, nil
   326  	}
   327  	return swag.WriteJSON(m)
   328  }
   329  
   330  // UnmarshalBinary interface implementation
   331  func (m *WritableProviderNetwork) UnmarshalBinary(b []byte) error {
   332  	var res WritableProviderNetwork
   333  	if err := swag.ReadJSON(b, &res); err != nil {
   334  		return err
   335  	}
   336  	*m = res
   337  	return nil
   338  }