github.com/digitalocean/go-netbox@v0.0.2/netbox/models/circuit_type.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  // CircuitType circuit type
    33  //
    34  // swagger:model CircuitType
    35  type CircuitType struct {
    36  
    37  	// Circuit count
    38  	// Read Only: true
    39  	CircuitCount int64 `json:"circuit_count,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  	// Slug
    73  	// Required: true
    74  	// Max Length: 100
    75  	// Min Length: 1
    76  	// Pattern: ^[-a-zA-Z0-9_]+$
    77  	Slug *string `json:"slug"`
    78  
    79  	// Url
    80  	// Read Only: true
    81  	// Format: uri
    82  	URL strfmt.URI `json:"url,omitempty"`
    83  }
    84  
    85  // Validate validates this circuit type
    86  func (m *CircuitType) 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.validateSlug(formats); err != nil {
   106  		res = append(res, err)
   107  	}
   108  
   109  	if err := m.validateURL(formats); err != nil {
   110  		res = append(res, err)
   111  	}
   112  
   113  	if len(res) > 0 {
   114  		return errors.CompositeValidationError(res...)
   115  	}
   116  	return nil
   117  }
   118  
   119  func (m *CircuitType) validateCreated(formats strfmt.Registry) error {
   120  	if swag.IsZero(m.Created) { // not required
   121  		return nil
   122  	}
   123  
   124  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   125  		return err
   126  	}
   127  
   128  	return nil
   129  }
   130  
   131  func (m *CircuitType) validateDescription(formats strfmt.Registry) error {
   132  	if swag.IsZero(m.Description) { // not required
   133  		return nil
   134  	}
   135  
   136  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   137  		return err
   138  	}
   139  
   140  	return nil
   141  }
   142  
   143  func (m *CircuitType) validateLastUpdated(formats strfmt.Registry) error {
   144  	if swag.IsZero(m.LastUpdated) { // not required
   145  		return nil
   146  	}
   147  
   148  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   149  		return err
   150  	}
   151  
   152  	return nil
   153  }
   154  
   155  func (m *CircuitType) validateName(formats strfmt.Registry) error {
   156  
   157  	if err := validate.Required("name", "body", m.Name); err != nil {
   158  		return err
   159  	}
   160  
   161  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   162  		return err
   163  	}
   164  
   165  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   166  		return err
   167  	}
   168  
   169  	return nil
   170  }
   171  
   172  func (m *CircuitType) validateSlug(formats strfmt.Registry) error {
   173  
   174  	if err := validate.Required("slug", "body", m.Slug); err != nil {
   175  		return err
   176  	}
   177  
   178  	if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil {
   179  		return err
   180  	}
   181  
   182  	if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil {
   183  		return err
   184  	}
   185  
   186  	if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil {
   187  		return err
   188  	}
   189  
   190  	return nil
   191  }
   192  
   193  func (m *CircuitType) validateURL(formats strfmt.Registry) error {
   194  	if swag.IsZero(m.URL) { // not required
   195  		return nil
   196  	}
   197  
   198  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   199  		return err
   200  	}
   201  
   202  	return nil
   203  }
   204  
   205  // ContextValidate validate this circuit type based on the context it is used
   206  func (m *CircuitType) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   207  	var res []error
   208  
   209  	if err := m.contextValidateCircuitCount(ctx, formats); err != nil {
   210  		res = append(res, err)
   211  	}
   212  
   213  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   214  		res = append(res, err)
   215  	}
   216  
   217  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   218  		res = append(res, err)
   219  	}
   220  
   221  	if err := m.contextValidateID(ctx, formats); err != nil {
   222  		res = append(res, err)
   223  	}
   224  
   225  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   226  		res = append(res, err)
   227  	}
   228  
   229  	if err := m.contextValidateURL(ctx, formats); err != nil {
   230  		res = append(res, err)
   231  	}
   232  
   233  	if len(res) > 0 {
   234  		return errors.CompositeValidationError(res...)
   235  	}
   236  	return nil
   237  }
   238  
   239  func (m *CircuitType) contextValidateCircuitCount(ctx context.Context, formats strfmt.Registry) error {
   240  
   241  	if err := validate.ReadOnly(ctx, "circuit_count", "body", int64(m.CircuitCount)); err != nil {
   242  		return err
   243  	}
   244  
   245  	return nil
   246  }
   247  
   248  func (m *CircuitType) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   249  
   250  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   251  		return err
   252  	}
   253  
   254  	return nil
   255  }
   256  
   257  func (m *CircuitType) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   258  
   259  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   260  		return err
   261  	}
   262  
   263  	return nil
   264  }
   265  
   266  func (m *CircuitType) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   267  
   268  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   269  		return err
   270  	}
   271  
   272  	return nil
   273  }
   274  
   275  func (m *CircuitType) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   276  
   277  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   278  		return err
   279  	}
   280  
   281  	return nil
   282  }
   283  
   284  func (m *CircuitType) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   285  
   286  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   287  		return err
   288  	}
   289  
   290  	return nil
   291  }
   292  
   293  // MarshalBinary interface implementation
   294  func (m *CircuitType) MarshalBinary() ([]byte, error) {
   295  	if m == nil {
   296  		return nil, nil
   297  	}
   298  	return swag.WriteJSON(m)
   299  }
   300  
   301  // UnmarshalBinary interface implementation
   302  func (m *CircuitType) UnmarshalBinary(b []byte) error {
   303  	var res CircuitType
   304  	if err := swag.ReadJSON(b, &res); err != nil {
   305  		return err
   306  	}
   307  	*m = res
   308  	return nil
   309  }