github.com/digitalocean/go-netbox@v0.0.2/netbox/models/tag.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  // Tag tag
    33  //
    34  // swagger:model Tag
    35  type Tag 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  	// Description
    44  	// Max Length: 200
    45  	Description string `json:"description,omitempty"`
    46  
    47  	// Display
    48  	// Read Only: true
    49  	Display string `json:"display,omitempty"`
    50  
    51  	// Id
    52  	// Read Only: true
    53  	ID int64 `json:"id,omitempty"`
    54  
    55  	// Name
    56  	// Required: true
    57  	// Max Length: 100
    58  	// Min Length: 1
    59  	Name *string `json:"name"`
    60  
    61  	// Slug
    62  	// Required: true
    63  	// Max Length: 100
    64  	// Min Length: 1
    65  	// Pattern: ^[-a-zA-Z0-9_]+$
    66  	Slug *string `json:"slug"`
    67  
    68  	// Tagged items
    69  	// Read Only: true
    70  	TaggedItems int64 `json:"tagged_items,omitempty"`
    71  
    72  	// Url
    73  	// Read Only: true
    74  	// Format: uri
    75  	URL strfmt.URI `json:"url,omitempty"`
    76  }
    77  
    78  // Validate validates this tag
    79  func (m *Tag) Validate(formats strfmt.Registry) error {
    80  	var res []error
    81  
    82  	if err := m.validateColor(formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if err := m.validateDescription(formats); err != nil {
    87  		res = append(res, err)
    88  	}
    89  
    90  	if err := m.validateName(formats); err != nil {
    91  		res = append(res, err)
    92  	}
    93  
    94  	if err := m.validateSlug(formats); err != nil {
    95  		res = append(res, err)
    96  	}
    97  
    98  	if err := m.validateURL(formats); err != nil {
    99  		res = append(res, err)
   100  	}
   101  
   102  	if len(res) > 0 {
   103  		return errors.CompositeValidationError(res...)
   104  	}
   105  	return nil
   106  }
   107  
   108  func (m *Tag) validateColor(formats strfmt.Registry) error {
   109  	if swag.IsZero(m.Color) { // not required
   110  		return nil
   111  	}
   112  
   113  	if err := validate.MinLength("color", "body", m.Color, 1); err != nil {
   114  		return err
   115  	}
   116  
   117  	if err := validate.MaxLength("color", "body", m.Color, 6); err != nil {
   118  		return err
   119  	}
   120  
   121  	if err := validate.Pattern("color", "body", m.Color, `^[0-9a-f]{6}$`); err != nil {
   122  		return err
   123  	}
   124  
   125  	return nil
   126  }
   127  
   128  func (m *Tag) validateDescription(formats strfmt.Registry) error {
   129  	if swag.IsZero(m.Description) { // not required
   130  		return nil
   131  	}
   132  
   133  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   134  		return err
   135  	}
   136  
   137  	return nil
   138  }
   139  
   140  func (m *Tag) validateName(formats strfmt.Registry) error {
   141  
   142  	if err := validate.Required("name", "body", m.Name); err != nil {
   143  		return err
   144  	}
   145  
   146  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   147  		return err
   148  	}
   149  
   150  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   151  		return err
   152  	}
   153  
   154  	return nil
   155  }
   156  
   157  func (m *Tag) validateSlug(formats strfmt.Registry) error {
   158  
   159  	if err := validate.Required("slug", "body", m.Slug); err != nil {
   160  		return err
   161  	}
   162  
   163  	if err := validate.MinLength("slug", "body", *m.Slug, 1); err != nil {
   164  		return err
   165  	}
   166  
   167  	if err := validate.MaxLength("slug", "body", *m.Slug, 100); err != nil {
   168  		return err
   169  	}
   170  
   171  	if err := validate.Pattern("slug", "body", *m.Slug, `^[-a-zA-Z0-9_]+$`); err != nil {
   172  		return err
   173  	}
   174  
   175  	return nil
   176  }
   177  
   178  func (m *Tag) validateURL(formats strfmt.Registry) error {
   179  	if swag.IsZero(m.URL) { // not required
   180  		return nil
   181  	}
   182  
   183  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   184  		return err
   185  	}
   186  
   187  	return nil
   188  }
   189  
   190  // ContextValidate validate this tag based on the context it is used
   191  func (m *Tag) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   192  	var res []error
   193  
   194  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   195  		res = append(res, err)
   196  	}
   197  
   198  	if err := m.contextValidateID(ctx, formats); err != nil {
   199  		res = append(res, err)
   200  	}
   201  
   202  	if err := m.contextValidateTaggedItems(ctx, formats); err != nil {
   203  		res = append(res, err)
   204  	}
   205  
   206  	if err := m.contextValidateURL(ctx, formats); err != nil {
   207  		res = append(res, err)
   208  	}
   209  
   210  	if len(res) > 0 {
   211  		return errors.CompositeValidationError(res...)
   212  	}
   213  	return nil
   214  }
   215  
   216  func (m *Tag) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   217  
   218  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   219  		return err
   220  	}
   221  
   222  	return nil
   223  }
   224  
   225  func (m *Tag) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   226  
   227  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   228  		return err
   229  	}
   230  
   231  	return nil
   232  }
   233  
   234  func (m *Tag) contextValidateTaggedItems(ctx context.Context, formats strfmt.Registry) error {
   235  
   236  	if err := validate.ReadOnly(ctx, "tagged_items", "body", int64(m.TaggedItems)); err != nil {
   237  		return err
   238  	}
   239  
   240  	return nil
   241  }
   242  
   243  func (m *Tag) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   244  
   245  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   246  		return err
   247  	}
   248  
   249  	return nil
   250  }
   251  
   252  // MarshalBinary interface implementation
   253  func (m *Tag) MarshalBinary() ([]byte, error) {
   254  	if m == nil {
   255  		return nil, nil
   256  	}
   257  	return swag.WriteJSON(m)
   258  }
   259  
   260  // UnmarshalBinary interface implementation
   261  func (m *Tag) UnmarshalBinary(b []byte) error {
   262  	var res Tag
   263  	if err := swag.ReadJSON(b, &res); err != nil {
   264  		return err
   265  	}
   266  	*m = res
   267  	return nil
   268  }