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