github.com/digitalocean/go-netbox@v0.0.2/netbox/models/rack_role.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  // RackRole rack role
    33  //
    34  // swagger:model RackRole
    35  type RackRole struct {
    36  
    37  	// Color
    38  	// Max Length: 6
    39  	// Min Length: 1
    40  	// Pattern: ^[0-9a-f]{6}$
    41  	Color string `json:"color,omitempty"`
    42  
    43  	// Created
    44  	// Read Only: true
    45  	// Format: date
    46  	Created strfmt.Date `json:"created,omitempty"`
    47  
    48  	// Custom fields
    49  	CustomFields interface{} `json:"custom_fields,omitempty"`
    50  
    51  	// Description
    52  	// Max Length: 200
    53  	Description string `json:"description,omitempty"`
    54  
    55  	// Display
    56  	// Read Only: true
    57  	Display string `json:"display,omitempty"`
    58  
    59  	// Id
    60  	// Read Only: true
    61  	ID int64 `json:"id,omitempty"`
    62  
    63  	// Last updated
    64  	// Read Only: true
    65  	// Format: date-time
    66  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    67  
    68  	// Name
    69  	// Required: true
    70  	// Max Length: 100
    71  	// Min Length: 1
    72  	Name *string `json:"name"`
    73  
    74  	// Rack count
    75  	// Read Only: true
    76  	RackCount int64 `json:"rack_count,omitempty"`
    77  
    78  	// Slug
    79  	// Required: true
    80  	// Max Length: 100
    81  	// Min Length: 1
    82  	// Pattern: ^[-a-zA-Z0-9_]+$
    83  	Slug *string `json:"slug"`
    84  
    85  	// Url
    86  	// Read Only: true
    87  	// Format: uri
    88  	URL strfmt.URI `json:"url,omitempty"`
    89  }
    90  
    91  // Validate validates this rack role
    92  func (m *RackRole) Validate(formats strfmt.Registry) error {
    93  	var res []error
    94  
    95  	if err := m.validateColor(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if err := m.validateCreated(formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := m.validateDescription(formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if err := m.validateLastUpdated(formats); err != nil {
   108  		res = append(res, err)
   109  	}
   110  
   111  	if err := m.validateName(formats); err != nil {
   112  		res = append(res, err)
   113  	}
   114  
   115  	if err := m.validateSlug(formats); err != nil {
   116  		res = append(res, err)
   117  	}
   118  
   119  	if err := m.validateURL(formats); err != nil {
   120  		res = append(res, err)
   121  	}
   122  
   123  	if len(res) > 0 {
   124  		return errors.CompositeValidationError(res...)
   125  	}
   126  	return nil
   127  }
   128  
   129  func (m *RackRole) validateColor(formats strfmt.Registry) error {
   130  	if swag.IsZero(m.Color) { // not required
   131  		return nil
   132  	}
   133  
   134  	if err := validate.MinLength("color", "body", m.Color, 1); err != nil {
   135  		return err
   136  	}
   137  
   138  	if err := validate.MaxLength("color", "body", m.Color, 6); err != nil {
   139  		return err
   140  	}
   141  
   142  	if err := validate.Pattern("color", "body", m.Color, `^[0-9a-f]{6}$`); err != nil {
   143  		return err
   144  	}
   145  
   146  	return nil
   147  }
   148  
   149  func (m *RackRole) validateCreated(formats strfmt.Registry) error {
   150  	if swag.IsZero(m.Created) { // not required
   151  		return nil
   152  	}
   153  
   154  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   155  		return err
   156  	}
   157  
   158  	return nil
   159  }
   160  
   161  func (m *RackRole) validateDescription(formats strfmt.Registry) error {
   162  	if swag.IsZero(m.Description) { // not required
   163  		return nil
   164  	}
   165  
   166  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   167  		return err
   168  	}
   169  
   170  	return nil
   171  }
   172  
   173  func (m *RackRole) validateLastUpdated(formats strfmt.Registry) error {
   174  	if swag.IsZero(m.LastUpdated) { // not required
   175  		return nil
   176  	}
   177  
   178  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   179  		return err
   180  	}
   181  
   182  	return nil
   183  }
   184  
   185  func (m *RackRole) validateName(formats strfmt.Registry) error {
   186  
   187  	if err := validate.Required("name", "body", m.Name); err != nil {
   188  		return err
   189  	}
   190  
   191  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   192  		return err
   193  	}
   194  
   195  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   196  		return err
   197  	}
   198  
   199  	return nil
   200  }
   201  
   202  func (m *RackRole) 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 *RackRole) 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 rack role based on the context it is used
   236  func (m *RackRole) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   237  	var res []error
   238  
   239  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   240  		res = append(res, err)
   241  	}
   242  
   243  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   244  		res = append(res, err)
   245  	}
   246  
   247  	if err := m.contextValidateID(ctx, formats); err != nil {
   248  		res = append(res, err)
   249  	}
   250  
   251  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   252  		res = append(res, err)
   253  	}
   254  
   255  	if err := m.contextValidateRackCount(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 *RackRole) 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 *RackRole) 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 *RackRole) 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 *RackRole) 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 *RackRole) contextValidateRackCount(ctx context.Context, formats strfmt.Registry) error {
   306  
   307  	if err := validate.ReadOnly(ctx, "rack_count", "body", int64(m.RackCount)); err != nil {
   308  		return err
   309  	}
   310  
   311  	return nil
   312  }
   313  
   314  func (m *RackRole) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   315  
   316  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   317  		return err
   318  	}
   319  
   320  	return nil
   321  }
   322  
   323  // MarshalBinary interface implementation
   324  func (m *RackRole) MarshalBinary() ([]byte, error) {
   325  	if m == nil {
   326  		return nil, nil
   327  	}
   328  	return swag.WriteJSON(m)
   329  }
   330  
   331  // UnmarshalBinary interface implementation
   332  func (m *RackRole) UnmarshalBinary(b []byte) error {
   333  	var res RackRole
   334  	if err := swag.ReadJSON(b, &res); err != nil {
   335  		return err
   336  	}
   337  	*m = res
   338  	return nil
   339  }