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