github.com/digitalocean/go-netbox@v0.0.2/netbox/models/power_panel.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  	"strconv"
    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  // PowerPanel power panel
    34  //
    35  // swagger:model PowerPanel
    36  type PowerPanel struct {
    37  
    38  	// Custom fields
    39  	CustomFields interface{} `json:"custom_fields,omitempty"`
    40  
    41  	// Display
    42  	// Read Only: true
    43  	Display string `json:"display,omitempty"`
    44  
    45  	// Id
    46  	// Read Only: true
    47  	ID int64 `json:"id,omitempty"`
    48  
    49  	// location
    50  	Location *NestedLocation `json:"location,omitempty"`
    51  
    52  	// Name
    53  	// Required: true
    54  	// Max Length: 100
    55  	// Min Length: 1
    56  	Name *string `json:"name"`
    57  
    58  	// Powerfeed count
    59  	// Read Only: true
    60  	PowerfeedCount int64 `json:"powerfeed_count,omitempty"`
    61  
    62  	// site
    63  	// Required: true
    64  	Site *NestedSite `json:"site"`
    65  
    66  	// tags
    67  	Tags []*NestedTag `json:"tags"`
    68  
    69  	// Url
    70  	// Read Only: true
    71  	// Format: uri
    72  	URL strfmt.URI `json:"url,omitempty"`
    73  }
    74  
    75  // Validate validates this power panel
    76  func (m *PowerPanel) Validate(formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.validateLocation(formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if err := m.validateName(formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	if err := m.validateSite(formats); err != nil {
    88  		res = append(res, err)
    89  	}
    90  
    91  	if err := m.validateTags(formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if err := m.validateURL(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if len(res) > 0 {
   100  		return errors.CompositeValidationError(res...)
   101  	}
   102  	return nil
   103  }
   104  
   105  func (m *PowerPanel) validateLocation(formats strfmt.Registry) error {
   106  	if swag.IsZero(m.Location) { // not required
   107  		return nil
   108  	}
   109  
   110  	if m.Location != nil {
   111  		if err := m.Location.Validate(formats); err != nil {
   112  			if ve, ok := err.(*errors.Validation); ok {
   113  				return ve.ValidateName("location")
   114  			} else if ce, ok := err.(*errors.CompositeError); ok {
   115  				return ce.ValidateName("location")
   116  			}
   117  			return err
   118  		}
   119  	}
   120  
   121  	return nil
   122  }
   123  
   124  func (m *PowerPanel) validateName(formats strfmt.Registry) error {
   125  
   126  	if err := validate.Required("name", "body", m.Name); err != nil {
   127  		return err
   128  	}
   129  
   130  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   131  		return err
   132  	}
   133  
   134  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   135  		return err
   136  	}
   137  
   138  	return nil
   139  }
   140  
   141  func (m *PowerPanel) validateSite(formats strfmt.Registry) error {
   142  
   143  	if err := validate.Required("site", "body", m.Site); err != nil {
   144  		return err
   145  	}
   146  
   147  	if m.Site != nil {
   148  		if err := m.Site.Validate(formats); err != nil {
   149  			if ve, ok := err.(*errors.Validation); ok {
   150  				return ve.ValidateName("site")
   151  			} else if ce, ok := err.(*errors.CompositeError); ok {
   152  				return ce.ValidateName("site")
   153  			}
   154  			return err
   155  		}
   156  	}
   157  
   158  	return nil
   159  }
   160  
   161  func (m *PowerPanel) validateTags(formats strfmt.Registry) error {
   162  	if swag.IsZero(m.Tags) { // not required
   163  		return nil
   164  	}
   165  
   166  	for i := 0; i < len(m.Tags); i++ {
   167  		if swag.IsZero(m.Tags[i]) { // not required
   168  			continue
   169  		}
   170  
   171  		if m.Tags[i] != nil {
   172  			if err := m.Tags[i].Validate(formats); err != nil {
   173  				if ve, ok := err.(*errors.Validation); ok {
   174  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   175  				} else if ce, ok := err.(*errors.CompositeError); ok {
   176  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   177  				}
   178  				return err
   179  			}
   180  		}
   181  
   182  	}
   183  
   184  	return nil
   185  }
   186  
   187  func (m *PowerPanel) validateURL(formats strfmt.Registry) error {
   188  	if swag.IsZero(m.URL) { // not required
   189  		return nil
   190  	}
   191  
   192  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   193  		return err
   194  	}
   195  
   196  	return nil
   197  }
   198  
   199  // ContextValidate validate this power panel based on the context it is used
   200  func (m *PowerPanel) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   201  	var res []error
   202  
   203  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   204  		res = append(res, err)
   205  	}
   206  
   207  	if err := m.contextValidateID(ctx, formats); err != nil {
   208  		res = append(res, err)
   209  	}
   210  
   211  	if err := m.contextValidateLocation(ctx, formats); err != nil {
   212  		res = append(res, err)
   213  	}
   214  
   215  	if err := m.contextValidatePowerfeedCount(ctx, formats); err != nil {
   216  		res = append(res, err)
   217  	}
   218  
   219  	if err := m.contextValidateSite(ctx, formats); err != nil {
   220  		res = append(res, err)
   221  	}
   222  
   223  	if err := m.contextValidateTags(ctx, formats); err != nil {
   224  		res = append(res, err)
   225  	}
   226  
   227  	if err := m.contextValidateURL(ctx, formats); err != nil {
   228  		res = append(res, err)
   229  	}
   230  
   231  	if len(res) > 0 {
   232  		return errors.CompositeValidationError(res...)
   233  	}
   234  	return nil
   235  }
   236  
   237  func (m *PowerPanel) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   238  
   239  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   240  		return err
   241  	}
   242  
   243  	return nil
   244  }
   245  
   246  func (m *PowerPanel) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   247  
   248  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   249  		return err
   250  	}
   251  
   252  	return nil
   253  }
   254  
   255  func (m *PowerPanel) contextValidateLocation(ctx context.Context, formats strfmt.Registry) error {
   256  
   257  	if m.Location != nil {
   258  		if err := m.Location.ContextValidate(ctx, formats); err != nil {
   259  			if ve, ok := err.(*errors.Validation); ok {
   260  				return ve.ValidateName("location")
   261  			} else if ce, ok := err.(*errors.CompositeError); ok {
   262  				return ce.ValidateName("location")
   263  			}
   264  			return err
   265  		}
   266  	}
   267  
   268  	return nil
   269  }
   270  
   271  func (m *PowerPanel) contextValidatePowerfeedCount(ctx context.Context, formats strfmt.Registry) error {
   272  
   273  	if err := validate.ReadOnly(ctx, "powerfeed_count", "body", int64(m.PowerfeedCount)); err != nil {
   274  		return err
   275  	}
   276  
   277  	return nil
   278  }
   279  
   280  func (m *PowerPanel) contextValidateSite(ctx context.Context, formats strfmt.Registry) error {
   281  
   282  	if m.Site != nil {
   283  		if err := m.Site.ContextValidate(ctx, formats); err != nil {
   284  			if ve, ok := err.(*errors.Validation); ok {
   285  				return ve.ValidateName("site")
   286  			} else if ce, ok := err.(*errors.CompositeError); ok {
   287  				return ce.ValidateName("site")
   288  			}
   289  			return err
   290  		}
   291  	}
   292  
   293  	return nil
   294  }
   295  
   296  func (m *PowerPanel) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   297  
   298  	for i := 0; i < len(m.Tags); i++ {
   299  
   300  		if m.Tags[i] != nil {
   301  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   302  				if ve, ok := err.(*errors.Validation); ok {
   303  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   304  				} else if ce, ok := err.(*errors.CompositeError); ok {
   305  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   306  				}
   307  				return err
   308  			}
   309  		}
   310  
   311  	}
   312  
   313  	return nil
   314  }
   315  
   316  func (m *PowerPanel) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   317  
   318  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   319  		return err
   320  	}
   321  
   322  	return nil
   323  }
   324  
   325  // MarshalBinary interface implementation
   326  func (m *PowerPanel) MarshalBinary() ([]byte, error) {
   327  	if m == nil {
   328  		return nil, nil
   329  	}
   330  	return swag.WriteJSON(m)
   331  }
   332  
   333  // UnmarshalBinary interface implementation
   334  func (m *PowerPanel) UnmarshalBinary(b []byte) error {
   335  	var res PowerPanel
   336  	if err := swag.ReadJSON(b, &res); err != nil {
   337  		return err
   338  	}
   339  	*m = res
   340  	return nil
   341  }