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