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