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