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