github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_vm_interface.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  // NestedVMInterface nested VM interface
    33  //
    34  // swagger:model NestedVMInterface
    35  type NestedVMInterface 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  	// Name
    46  	// Required: true
    47  	// Max Length: 64
    48  	// Min Length: 1
    49  	Name *string `json:"name"`
    50  
    51  	// Url
    52  	// Read Only: true
    53  	// Format: uri
    54  	URL strfmt.URI `json:"url,omitempty"`
    55  
    56  	// virtual machine
    57  	VirtualMachine *NestedVirtualMachine `json:"virtual_machine,omitempty"`
    58  }
    59  
    60  // Validate validates this nested VM interface
    61  func (m *NestedVMInterface) Validate(formats strfmt.Registry) error {
    62  	var res []error
    63  
    64  	if err := m.validateName(formats); err != nil {
    65  		res = append(res, err)
    66  	}
    67  
    68  	if err := m.validateURL(formats); err != nil {
    69  		res = append(res, err)
    70  	}
    71  
    72  	if err := m.validateVirtualMachine(formats); err != nil {
    73  		res = append(res, err)
    74  	}
    75  
    76  	if len(res) > 0 {
    77  		return errors.CompositeValidationError(res...)
    78  	}
    79  	return nil
    80  }
    81  
    82  func (m *NestedVMInterface) validateName(formats strfmt.Registry) error {
    83  
    84  	if err := validate.Required("name", "body", m.Name); err != nil {
    85  		return err
    86  	}
    87  
    88  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
    89  		return err
    90  	}
    91  
    92  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
    93  		return err
    94  	}
    95  
    96  	return nil
    97  }
    98  
    99  func (m *NestedVMInterface) validateURL(formats strfmt.Registry) error {
   100  	if swag.IsZero(m.URL) { // not required
   101  		return nil
   102  	}
   103  
   104  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   105  		return err
   106  	}
   107  
   108  	return nil
   109  }
   110  
   111  func (m *NestedVMInterface) validateVirtualMachine(formats strfmt.Registry) error {
   112  	if swag.IsZero(m.VirtualMachine) { // not required
   113  		return nil
   114  	}
   115  
   116  	if m.VirtualMachine != nil {
   117  		if err := m.VirtualMachine.Validate(formats); err != nil {
   118  			if ve, ok := err.(*errors.Validation); ok {
   119  				return ve.ValidateName("virtual_machine")
   120  			} else if ce, ok := err.(*errors.CompositeError); ok {
   121  				return ce.ValidateName("virtual_machine")
   122  			}
   123  			return err
   124  		}
   125  	}
   126  
   127  	return nil
   128  }
   129  
   130  // ContextValidate validate this nested VM interface based on the context it is used
   131  func (m *NestedVMInterface) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   132  	var res []error
   133  
   134  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   135  		res = append(res, err)
   136  	}
   137  
   138  	if err := m.contextValidateID(ctx, formats); err != nil {
   139  		res = append(res, err)
   140  	}
   141  
   142  	if err := m.contextValidateURL(ctx, formats); err != nil {
   143  		res = append(res, err)
   144  	}
   145  
   146  	if err := m.contextValidateVirtualMachine(ctx, formats); err != nil {
   147  		res = append(res, err)
   148  	}
   149  
   150  	if len(res) > 0 {
   151  		return errors.CompositeValidationError(res...)
   152  	}
   153  	return nil
   154  }
   155  
   156  func (m *NestedVMInterface) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   157  
   158  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   159  		return err
   160  	}
   161  
   162  	return nil
   163  }
   164  
   165  func (m *NestedVMInterface) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   166  
   167  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   168  		return err
   169  	}
   170  
   171  	return nil
   172  }
   173  
   174  func (m *NestedVMInterface) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   175  
   176  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   177  		return err
   178  	}
   179  
   180  	return nil
   181  }
   182  
   183  func (m *NestedVMInterface) contextValidateVirtualMachine(ctx context.Context, formats strfmt.Registry) error {
   184  
   185  	if m.VirtualMachine != nil {
   186  		if err := m.VirtualMachine.ContextValidate(ctx, formats); err != nil {
   187  			if ve, ok := err.(*errors.Validation); ok {
   188  				return ve.ValidateName("virtual_machine")
   189  			} else if ce, ok := err.(*errors.CompositeError); ok {
   190  				return ce.ValidateName("virtual_machine")
   191  			}
   192  			return err
   193  		}
   194  	}
   195  
   196  	return nil
   197  }
   198  
   199  // MarshalBinary interface implementation
   200  func (m *NestedVMInterface) MarshalBinary() ([]byte, error) {
   201  	if m == nil {
   202  		return nil, nil
   203  	}
   204  	return swag.WriteJSON(m)
   205  }
   206  
   207  // UnmarshalBinary interface implementation
   208  func (m *NestedVMInterface) UnmarshalBinary(b []byte) error {
   209  	var res NestedVMInterface
   210  	if err := swag.ReadJSON(b, &res); err != nil {
   211  		return err
   212  	}
   213  	*m = res
   214  	return nil
   215  }