github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_cable.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  // NestedCable nested cable
    33  //
    34  // swagger:model NestedCable
    35  type NestedCable struct {
    36  
    37  	// Display
    38  	// Read Only: true
    39  	Display string `json:"display,omitempty"`
    40  
    41  	// Id
    42  	// Read Only: true
    43  	ID int64 `json:"id,omitempty"`
    44  
    45  	// Label
    46  	// Max Length: 100
    47  	Label string `json:"label,omitempty"`
    48  
    49  	// Url
    50  	// Read Only: true
    51  	// Format: uri
    52  	URL strfmt.URI `json:"url,omitempty"`
    53  }
    54  
    55  // Validate validates this nested cable
    56  func (m *NestedCable) Validate(formats strfmt.Registry) error {
    57  	var res []error
    58  
    59  	if err := m.validateLabel(formats); err != nil {
    60  		res = append(res, err)
    61  	}
    62  
    63  	if err := m.validateURL(formats); err != nil {
    64  		res = append(res, err)
    65  	}
    66  
    67  	if len(res) > 0 {
    68  		return errors.CompositeValidationError(res...)
    69  	}
    70  	return nil
    71  }
    72  
    73  func (m *NestedCable) validateLabel(formats strfmt.Registry) error {
    74  	if swag.IsZero(m.Label) { // not required
    75  		return nil
    76  	}
    77  
    78  	if err := validate.MaxLength("label", "body", m.Label, 100); err != nil {
    79  		return err
    80  	}
    81  
    82  	return nil
    83  }
    84  
    85  func (m *NestedCable) validateURL(formats strfmt.Registry) error {
    86  	if swag.IsZero(m.URL) { // not required
    87  		return nil
    88  	}
    89  
    90  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
    91  		return err
    92  	}
    93  
    94  	return nil
    95  }
    96  
    97  // ContextValidate validate this nested cable based on the context it is used
    98  func (m *NestedCable) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    99  	var res []error
   100  
   101  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   102  		res = append(res, err)
   103  	}
   104  
   105  	if err := m.contextValidateID(ctx, formats); err != nil {
   106  		res = append(res, err)
   107  	}
   108  
   109  	if err := m.contextValidateURL(ctx, 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 *NestedCable) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   120  
   121  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   122  		return err
   123  	}
   124  
   125  	return nil
   126  }
   127  
   128  func (m *NestedCable) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   129  
   130  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   131  		return err
   132  	}
   133  
   134  	return nil
   135  }
   136  
   137  func (m *NestedCable) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   138  
   139  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   140  		return err
   141  	}
   142  
   143  	return nil
   144  }
   145  
   146  // MarshalBinary interface implementation
   147  func (m *NestedCable) MarshalBinary() ([]byte, error) {
   148  	if m == nil {
   149  		return nil, nil
   150  	}
   151  	return swag.WriteJSON(m)
   152  }
   153  
   154  // UnmarshalBinary interface implementation
   155  func (m *NestedCable) UnmarshalBinary(b []byte) error {
   156  	var res NestedCable
   157  	if err := swag.ReadJSON(b, &res); err != nil {
   158  		return err
   159  	}
   160  	*m = res
   161  	return nil
   162  }