github.com/digitalocean/go-netbox@v0.0.2/netbox/models/custom_link.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  	"encoding/json"
    26  
    27  	"github.com/go-openapi/errors"
    28  	"github.com/go-openapi/strfmt"
    29  	"github.com/go-openapi/swag"
    30  	"github.com/go-openapi/validate"
    31  )
    32  
    33  // CustomLink custom link
    34  //
    35  // swagger:model CustomLink
    36  type CustomLink struct {
    37  
    38  	// Button class
    39  	//
    40  	// The class of the first link in a group will be used for the dropdown button
    41  	// Enum: [default primary success info warning danger link]
    42  	ButtonClass string `json:"button_class,omitempty"`
    43  
    44  	// Content type
    45  	// Required: true
    46  	ContentType *string `json:"content_type"`
    47  
    48  	// Display
    49  	// Read Only: true
    50  	Display string `json:"display,omitempty"`
    51  
    52  	// Group name
    53  	//
    54  	// Links with the same group will appear as a dropdown menu
    55  	// Max Length: 50
    56  	GroupName string `json:"group_name,omitempty"`
    57  
    58  	// Id
    59  	// Read Only: true
    60  	ID int64 `json:"id,omitempty"`
    61  
    62  	// Link text
    63  	//
    64  	// Jinja2 template code for link text
    65  	// Required: true
    66  	// Max Length: 500
    67  	// Min Length: 1
    68  	LinkText *string `json:"link_text"`
    69  
    70  	// Link URL
    71  	//
    72  	// Jinja2 template code for link URL
    73  	// Required: true
    74  	// Max Length: 500
    75  	// Min Length: 1
    76  	LinkURL *string `json:"link_url"`
    77  
    78  	// Name
    79  	// Required: true
    80  	// Max Length: 100
    81  	// Min Length: 1
    82  	Name *string `json:"name"`
    83  
    84  	// New window
    85  	//
    86  	// Force link to open in a new window
    87  	NewWindow bool `json:"new_window,omitempty"`
    88  
    89  	// Url
    90  	// Read Only: true
    91  	// Format: uri
    92  	URL strfmt.URI `json:"url,omitempty"`
    93  
    94  	// Weight
    95  	// Maximum: 32767
    96  	// Minimum: 0
    97  	Weight *int64 `json:"weight,omitempty"`
    98  }
    99  
   100  // Validate validates this custom link
   101  func (m *CustomLink) Validate(formats strfmt.Registry) error {
   102  	var res []error
   103  
   104  	if err := m.validateButtonClass(formats); err != nil {
   105  		res = append(res, err)
   106  	}
   107  
   108  	if err := m.validateContentType(formats); err != nil {
   109  		res = append(res, err)
   110  	}
   111  
   112  	if err := m.validateGroupName(formats); err != nil {
   113  		res = append(res, err)
   114  	}
   115  
   116  	if err := m.validateLinkText(formats); err != nil {
   117  		res = append(res, err)
   118  	}
   119  
   120  	if err := m.validateLinkURL(formats); err != nil {
   121  		res = append(res, err)
   122  	}
   123  
   124  	if err := m.validateName(formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	if err := m.validateURL(formats); err != nil {
   129  		res = append(res, err)
   130  	}
   131  
   132  	if err := m.validateWeight(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  var customLinkTypeButtonClassPropEnum []interface{}
   143  
   144  func init() {
   145  	var res []string
   146  	if err := json.Unmarshal([]byte(`["default","primary","success","info","warning","danger","link"]`), &res); err != nil {
   147  		panic(err)
   148  	}
   149  	for _, v := range res {
   150  		customLinkTypeButtonClassPropEnum = append(customLinkTypeButtonClassPropEnum, v)
   151  	}
   152  }
   153  
   154  const (
   155  
   156  	// CustomLinkButtonClassDefault captures enum value "default"
   157  	CustomLinkButtonClassDefault string = "default"
   158  
   159  	// CustomLinkButtonClassPrimary captures enum value "primary"
   160  	CustomLinkButtonClassPrimary string = "primary"
   161  
   162  	// CustomLinkButtonClassSuccess captures enum value "success"
   163  	CustomLinkButtonClassSuccess string = "success"
   164  
   165  	// CustomLinkButtonClassInfo captures enum value "info"
   166  	CustomLinkButtonClassInfo string = "info"
   167  
   168  	// CustomLinkButtonClassWarning captures enum value "warning"
   169  	CustomLinkButtonClassWarning string = "warning"
   170  
   171  	// CustomLinkButtonClassDanger captures enum value "danger"
   172  	CustomLinkButtonClassDanger string = "danger"
   173  
   174  	// CustomLinkButtonClassLink captures enum value "link"
   175  	CustomLinkButtonClassLink string = "link"
   176  )
   177  
   178  // prop value enum
   179  func (m *CustomLink) validateButtonClassEnum(path, location string, value string) error {
   180  	if err := validate.EnumCase(path, location, value, customLinkTypeButtonClassPropEnum, true); err != nil {
   181  		return err
   182  	}
   183  	return nil
   184  }
   185  
   186  func (m *CustomLink) validateButtonClass(formats strfmt.Registry) error {
   187  	if swag.IsZero(m.ButtonClass) { // not required
   188  		return nil
   189  	}
   190  
   191  	// value enum
   192  	if err := m.validateButtonClassEnum("button_class", "body", m.ButtonClass); err != nil {
   193  		return err
   194  	}
   195  
   196  	return nil
   197  }
   198  
   199  func (m *CustomLink) validateContentType(formats strfmt.Registry) error {
   200  
   201  	if err := validate.Required("content_type", "body", m.ContentType); err != nil {
   202  		return err
   203  	}
   204  
   205  	return nil
   206  }
   207  
   208  func (m *CustomLink) validateGroupName(formats strfmt.Registry) error {
   209  	if swag.IsZero(m.GroupName) { // not required
   210  		return nil
   211  	}
   212  
   213  	if err := validate.MaxLength("group_name", "body", m.GroupName, 50); err != nil {
   214  		return err
   215  	}
   216  
   217  	return nil
   218  }
   219  
   220  func (m *CustomLink) validateLinkText(formats strfmt.Registry) error {
   221  
   222  	if err := validate.Required("link_text", "body", m.LinkText); err != nil {
   223  		return err
   224  	}
   225  
   226  	if err := validate.MinLength("link_text", "body", *m.LinkText, 1); err != nil {
   227  		return err
   228  	}
   229  
   230  	if err := validate.MaxLength("link_text", "body", *m.LinkText, 500); err != nil {
   231  		return err
   232  	}
   233  
   234  	return nil
   235  }
   236  
   237  func (m *CustomLink) validateLinkURL(formats strfmt.Registry) error {
   238  
   239  	if err := validate.Required("link_url", "body", m.LinkURL); err != nil {
   240  		return err
   241  	}
   242  
   243  	if err := validate.MinLength("link_url", "body", *m.LinkURL, 1); err != nil {
   244  		return err
   245  	}
   246  
   247  	if err := validate.MaxLength("link_url", "body", *m.LinkURL, 500); err != nil {
   248  		return err
   249  	}
   250  
   251  	return nil
   252  }
   253  
   254  func (m *CustomLink) validateName(formats strfmt.Registry) error {
   255  
   256  	if err := validate.Required("name", "body", m.Name); err != nil {
   257  		return err
   258  	}
   259  
   260  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   261  		return err
   262  	}
   263  
   264  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   265  		return err
   266  	}
   267  
   268  	return nil
   269  }
   270  
   271  func (m *CustomLink) validateURL(formats strfmt.Registry) error {
   272  	if swag.IsZero(m.URL) { // not required
   273  		return nil
   274  	}
   275  
   276  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   277  		return err
   278  	}
   279  
   280  	return nil
   281  }
   282  
   283  func (m *CustomLink) validateWeight(formats strfmt.Registry) error {
   284  	if swag.IsZero(m.Weight) { // not required
   285  		return nil
   286  	}
   287  
   288  	if err := validate.MinimumInt("weight", "body", *m.Weight, 0, false); err != nil {
   289  		return err
   290  	}
   291  
   292  	if err := validate.MaximumInt("weight", "body", *m.Weight, 32767, false); err != nil {
   293  		return err
   294  	}
   295  
   296  	return nil
   297  }
   298  
   299  // ContextValidate validate this custom link based on the context it is used
   300  func (m *CustomLink) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   301  	var res []error
   302  
   303  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   304  		res = append(res, err)
   305  	}
   306  
   307  	if err := m.contextValidateID(ctx, formats); err != nil {
   308  		res = append(res, err)
   309  	}
   310  
   311  	if err := m.contextValidateURL(ctx, formats); err != nil {
   312  		res = append(res, err)
   313  	}
   314  
   315  	if len(res) > 0 {
   316  		return errors.CompositeValidationError(res...)
   317  	}
   318  	return nil
   319  }
   320  
   321  func (m *CustomLink) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   322  
   323  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   324  		return err
   325  	}
   326  
   327  	return nil
   328  }
   329  
   330  func (m *CustomLink) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   331  
   332  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   333  		return err
   334  	}
   335  
   336  	return nil
   337  }
   338  
   339  func (m *CustomLink) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   340  
   341  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   342  		return err
   343  	}
   344  
   345  	return nil
   346  }
   347  
   348  // MarshalBinary interface implementation
   349  func (m *CustomLink) MarshalBinary() ([]byte, error) {
   350  	if m == nil {
   351  		return nil, nil
   352  	}
   353  	return swag.WriteJSON(m)
   354  }
   355  
   356  // UnmarshalBinary interface implementation
   357  func (m *CustomLink) UnmarshalBinary(b []byte) error {
   358  	var res CustomLink
   359  	if err := swag.ReadJSON(b, &res); err != nil {
   360  		return err
   361  	}
   362  	*m = res
   363  	return nil
   364  }