github.com/digitalocean/go-netbox@v0.0.2/netbox/client/ipam/ipam_roles_list_responses.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 ipam
    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  	"fmt"
    26  	"io"
    27  	"strconv"
    28  
    29  	"github.com/go-openapi/errors"
    30  	"github.com/go-openapi/runtime"
    31  	"github.com/go-openapi/strfmt"
    32  	"github.com/go-openapi/swag"
    33  	"github.com/go-openapi/validate"
    34  
    35  	"github.com/digitalocean/go-netbox/netbox/models"
    36  )
    37  
    38  // IpamRolesListReader is a Reader for the IpamRolesList structure.
    39  type IpamRolesListReader struct {
    40  	formats strfmt.Registry
    41  }
    42  
    43  // ReadResponse reads a server response into the received o.
    44  func (o *IpamRolesListReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
    45  	switch response.Code() {
    46  	case 200:
    47  		result := NewIpamRolesListOK()
    48  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    49  			return nil, err
    50  		}
    51  		return result, nil
    52  	default:
    53  		return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
    54  	}
    55  }
    56  
    57  // NewIpamRolesListOK creates a IpamRolesListOK with default headers values
    58  func NewIpamRolesListOK() *IpamRolesListOK {
    59  	return &IpamRolesListOK{}
    60  }
    61  
    62  /* IpamRolesListOK describes a response with status code 200, with default header values.
    63  
    64  IpamRolesListOK ipam roles list o k
    65  */
    66  type IpamRolesListOK struct {
    67  	Payload *IpamRolesListOKBody
    68  }
    69  
    70  func (o *IpamRolesListOK) Error() string {
    71  	return fmt.Sprintf("[GET /ipam/roles/][%d] ipamRolesListOK  %+v", 200, o.Payload)
    72  }
    73  func (o *IpamRolesListOK) GetPayload() *IpamRolesListOKBody {
    74  	return o.Payload
    75  }
    76  
    77  func (o *IpamRolesListOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    78  
    79  	o.Payload = new(IpamRolesListOKBody)
    80  
    81  	// response payload
    82  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
    83  		return err
    84  	}
    85  
    86  	return nil
    87  }
    88  
    89  /*IpamRolesListOKBody ipam roles list o k body
    90  swagger:model IpamRolesListOKBody
    91  */
    92  type IpamRolesListOKBody struct {
    93  
    94  	// count
    95  	// Required: true
    96  	Count *int64 `json:"count"`
    97  
    98  	// next
    99  	// Format: uri
   100  	Next *strfmt.URI `json:"next,omitempty"`
   101  
   102  	// previous
   103  	// Format: uri
   104  	Previous *strfmt.URI `json:"previous,omitempty"`
   105  
   106  	// results
   107  	// Required: true
   108  	Results []*models.Role `json:"results"`
   109  }
   110  
   111  // Validate validates this ipam roles list o k body
   112  func (o *IpamRolesListOKBody) Validate(formats strfmt.Registry) error {
   113  	var res []error
   114  
   115  	if err := o.validateCount(formats); err != nil {
   116  		res = append(res, err)
   117  	}
   118  
   119  	if err := o.validateNext(formats); err != nil {
   120  		res = append(res, err)
   121  	}
   122  
   123  	if err := o.validatePrevious(formats); err != nil {
   124  		res = append(res, err)
   125  	}
   126  
   127  	if err := o.validateResults(formats); err != nil {
   128  		res = append(res, err)
   129  	}
   130  
   131  	if len(res) > 0 {
   132  		return errors.CompositeValidationError(res...)
   133  	}
   134  	return nil
   135  }
   136  
   137  func (o *IpamRolesListOKBody) validateCount(formats strfmt.Registry) error {
   138  
   139  	if err := validate.Required("ipamRolesListOK"+"."+"count", "body", o.Count); err != nil {
   140  		return err
   141  	}
   142  
   143  	return nil
   144  }
   145  
   146  func (o *IpamRolesListOKBody) validateNext(formats strfmt.Registry) error {
   147  	if swag.IsZero(o.Next) { // not required
   148  		return nil
   149  	}
   150  
   151  	if err := validate.FormatOf("ipamRolesListOK"+"."+"next", "body", "uri", o.Next.String(), formats); err != nil {
   152  		return err
   153  	}
   154  
   155  	return nil
   156  }
   157  
   158  func (o *IpamRolesListOKBody) validatePrevious(formats strfmt.Registry) error {
   159  	if swag.IsZero(o.Previous) { // not required
   160  		return nil
   161  	}
   162  
   163  	if err := validate.FormatOf("ipamRolesListOK"+"."+"previous", "body", "uri", o.Previous.String(), formats); err != nil {
   164  		return err
   165  	}
   166  
   167  	return nil
   168  }
   169  
   170  func (o *IpamRolesListOKBody) validateResults(formats strfmt.Registry) error {
   171  
   172  	if err := validate.Required("ipamRolesListOK"+"."+"results", "body", o.Results); err != nil {
   173  		return err
   174  	}
   175  
   176  	for i := 0; i < len(o.Results); i++ {
   177  		if swag.IsZero(o.Results[i]) { // not required
   178  			continue
   179  		}
   180  
   181  		if o.Results[i] != nil {
   182  			if err := o.Results[i].Validate(formats); err != nil {
   183  				if ve, ok := err.(*errors.Validation); ok {
   184  					return ve.ValidateName("ipamRolesListOK" + "." + "results" + "." + strconv.Itoa(i))
   185  				} else if ce, ok := err.(*errors.CompositeError); ok {
   186  					return ce.ValidateName("ipamRolesListOK" + "." + "results" + "." + strconv.Itoa(i))
   187  				}
   188  				return err
   189  			}
   190  		}
   191  
   192  	}
   193  
   194  	return nil
   195  }
   196  
   197  // ContextValidate validate this ipam roles list o k body based on the context it is used
   198  func (o *IpamRolesListOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   199  	var res []error
   200  
   201  	if err := o.contextValidateResults(ctx, formats); err != nil {
   202  		res = append(res, err)
   203  	}
   204  
   205  	if len(res) > 0 {
   206  		return errors.CompositeValidationError(res...)
   207  	}
   208  	return nil
   209  }
   210  
   211  func (o *IpamRolesListOKBody) contextValidateResults(ctx context.Context, formats strfmt.Registry) error {
   212  
   213  	for i := 0; i < len(o.Results); i++ {
   214  
   215  		if o.Results[i] != nil {
   216  			if err := o.Results[i].ContextValidate(ctx, formats); err != nil {
   217  				if ve, ok := err.(*errors.Validation); ok {
   218  					return ve.ValidateName("ipamRolesListOK" + "." + "results" + "." + strconv.Itoa(i))
   219  				} else if ce, ok := err.(*errors.CompositeError); ok {
   220  					return ce.ValidateName("ipamRolesListOK" + "." + "results" + "." + strconv.Itoa(i))
   221  				}
   222  				return err
   223  			}
   224  		}
   225  
   226  	}
   227  
   228  	return nil
   229  }
   230  
   231  // MarshalBinary interface implementation
   232  func (o *IpamRolesListOKBody) MarshalBinary() ([]byte, error) {
   233  	if o == nil {
   234  		return nil, nil
   235  	}
   236  	return swag.WriteJSON(o)
   237  }
   238  
   239  // UnmarshalBinary interface implementation
   240  func (o *IpamRolesListOKBody) UnmarshalBinary(b []byte) error {
   241  	var res IpamRolesListOKBody
   242  	if err := swag.ReadJSON(b, &res); err != nil {
   243  		return err
   244  	}
   245  	*o = res
   246  	return nil
   247  }