github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_service.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  	"encoding/json"
    26  	"strconv"
    27  
    28  	"github.com/go-openapi/errors"
    29  	"github.com/go-openapi/strfmt"
    30  	"github.com/go-openapi/swag"
    31  	"github.com/go-openapi/validate"
    32  )
    33  
    34  // WritableService writable service
    35  //
    36  // swagger:model WritableService
    37  type WritableService struct {
    38  
    39  	// Created
    40  	// Read Only: true
    41  	// Format: date
    42  	Created strfmt.Date `json:"created,omitempty"`
    43  
    44  	// Custom fields
    45  	CustomFields interface{} `json:"custom_fields,omitempty"`
    46  
    47  	// Description
    48  	// Max Length: 200
    49  	Description string `json:"description,omitempty"`
    50  
    51  	// Device
    52  	Device *int64 `json:"device,omitempty"`
    53  
    54  	// Display
    55  	// Read Only: true
    56  	Display string `json:"display,omitempty"`
    57  
    58  	// Id
    59  	// Read Only: true
    60  	ID int64 `json:"id,omitempty"`
    61  
    62  	// ipaddresses
    63  	// Unique: true
    64  	Ipaddresses []int64 `json:"ipaddresses"`
    65  
    66  	// Last updated
    67  	// Read Only: true
    68  	// Format: date-time
    69  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    70  
    71  	// Name
    72  	// Required: true
    73  	// Max Length: 100
    74  	// Min Length: 1
    75  	Name *string `json:"name"`
    76  
    77  	// ports
    78  	// Required: true
    79  	Ports []int64 `json:"ports"`
    80  
    81  	// Protocol
    82  	// Required: true
    83  	// Enum: [tcp udp]
    84  	Protocol *string `json:"protocol"`
    85  
    86  	// tags
    87  	Tags []*NestedTag `json:"tags"`
    88  
    89  	// Url
    90  	// Read Only: true
    91  	// Format: uri
    92  	URL strfmt.URI `json:"url,omitempty"`
    93  
    94  	// Virtual machine
    95  	VirtualMachine *int64 `json:"virtual_machine,omitempty"`
    96  }
    97  
    98  // Validate validates this writable service
    99  func (m *WritableService) Validate(formats strfmt.Registry) error {
   100  	var res []error
   101  
   102  	if err := m.validateCreated(formats); err != nil {
   103  		res = append(res, err)
   104  	}
   105  
   106  	if err := m.validateDescription(formats); err != nil {
   107  		res = append(res, err)
   108  	}
   109  
   110  	if err := m.validateIpaddresses(formats); err != nil {
   111  		res = append(res, err)
   112  	}
   113  
   114  	if err := m.validateLastUpdated(formats); err != nil {
   115  		res = append(res, err)
   116  	}
   117  
   118  	if err := m.validateName(formats); err != nil {
   119  		res = append(res, err)
   120  	}
   121  
   122  	if err := m.validatePorts(formats); err != nil {
   123  		res = append(res, err)
   124  	}
   125  
   126  	if err := m.validateProtocol(formats); err != nil {
   127  		res = append(res, err)
   128  	}
   129  
   130  	if err := m.validateTags(formats); err != nil {
   131  		res = append(res, err)
   132  	}
   133  
   134  	if err := m.validateURL(formats); err != nil {
   135  		res = append(res, err)
   136  	}
   137  
   138  	if len(res) > 0 {
   139  		return errors.CompositeValidationError(res...)
   140  	}
   141  	return nil
   142  }
   143  
   144  func (m *WritableService) validateCreated(formats strfmt.Registry) error {
   145  	if swag.IsZero(m.Created) { // not required
   146  		return nil
   147  	}
   148  
   149  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   150  		return err
   151  	}
   152  
   153  	return nil
   154  }
   155  
   156  func (m *WritableService) validateDescription(formats strfmt.Registry) error {
   157  	if swag.IsZero(m.Description) { // not required
   158  		return nil
   159  	}
   160  
   161  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   162  		return err
   163  	}
   164  
   165  	return nil
   166  }
   167  
   168  func (m *WritableService) validateIpaddresses(formats strfmt.Registry) error {
   169  	if swag.IsZero(m.Ipaddresses) { // not required
   170  		return nil
   171  	}
   172  
   173  	if err := validate.UniqueItems("ipaddresses", "body", m.Ipaddresses); err != nil {
   174  		return err
   175  	}
   176  
   177  	return nil
   178  }
   179  
   180  func (m *WritableService) validateLastUpdated(formats strfmt.Registry) error {
   181  	if swag.IsZero(m.LastUpdated) { // not required
   182  		return nil
   183  	}
   184  
   185  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   186  		return err
   187  	}
   188  
   189  	return nil
   190  }
   191  
   192  func (m *WritableService) validateName(formats strfmt.Registry) error {
   193  
   194  	if err := validate.Required("name", "body", m.Name); err != nil {
   195  		return err
   196  	}
   197  
   198  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   199  		return err
   200  	}
   201  
   202  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   203  		return err
   204  	}
   205  
   206  	return nil
   207  }
   208  
   209  func (m *WritableService) validatePorts(formats strfmt.Registry) error {
   210  
   211  	if err := validate.Required("ports", "body", m.Ports); err != nil {
   212  		return err
   213  	}
   214  
   215  	for i := 0; i < len(m.Ports); i++ {
   216  
   217  		if err := validate.MinimumInt("ports"+"."+strconv.Itoa(i), "body", m.Ports[i], 1, false); err != nil {
   218  			return err
   219  		}
   220  
   221  		if err := validate.MaximumInt("ports"+"."+strconv.Itoa(i), "body", m.Ports[i], 65535, false); err != nil {
   222  			return err
   223  		}
   224  
   225  	}
   226  
   227  	return nil
   228  }
   229  
   230  var writableServiceTypeProtocolPropEnum []interface{}
   231  
   232  func init() {
   233  	var res []string
   234  	if err := json.Unmarshal([]byte(`["tcp","udp"]`), &res); err != nil {
   235  		panic(err)
   236  	}
   237  	for _, v := range res {
   238  		writableServiceTypeProtocolPropEnum = append(writableServiceTypeProtocolPropEnum, v)
   239  	}
   240  }
   241  
   242  const (
   243  
   244  	// WritableServiceProtocolTCP captures enum value "tcp"
   245  	WritableServiceProtocolTCP string = "tcp"
   246  
   247  	// WritableServiceProtocolUDP captures enum value "udp"
   248  	WritableServiceProtocolUDP string = "udp"
   249  )
   250  
   251  // prop value enum
   252  func (m *WritableService) validateProtocolEnum(path, location string, value string) error {
   253  	if err := validate.EnumCase(path, location, value, writableServiceTypeProtocolPropEnum, true); err != nil {
   254  		return err
   255  	}
   256  	return nil
   257  }
   258  
   259  func (m *WritableService) validateProtocol(formats strfmt.Registry) error {
   260  
   261  	if err := validate.Required("protocol", "body", m.Protocol); err != nil {
   262  		return err
   263  	}
   264  
   265  	// value enum
   266  	if err := m.validateProtocolEnum("protocol", "body", *m.Protocol); err != nil {
   267  		return err
   268  	}
   269  
   270  	return nil
   271  }
   272  
   273  func (m *WritableService) validateTags(formats strfmt.Registry) error {
   274  	if swag.IsZero(m.Tags) { // not required
   275  		return nil
   276  	}
   277  
   278  	for i := 0; i < len(m.Tags); i++ {
   279  		if swag.IsZero(m.Tags[i]) { // not required
   280  			continue
   281  		}
   282  
   283  		if m.Tags[i] != nil {
   284  			if err := m.Tags[i].Validate(formats); err != nil {
   285  				if ve, ok := err.(*errors.Validation); ok {
   286  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   287  				} else if ce, ok := err.(*errors.CompositeError); ok {
   288  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   289  				}
   290  				return err
   291  			}
   292  		}
   293  
   294  	}
   295  
   296  	return nil
   297  }
   298  
   299  func (m *WritableService) validateURL(formats strfmt.Registry) error {
   300  	if swag.IsZero(m.URL) { // not required
   301  		return nil
   302  	}
   303  
   304  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   305  		return err
   306  	}
   307  
   308  	return nil
   309  }
   310  
   311  // ContextValidate validate this writable service based on the context it is used
   312  func (m *WritableService) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   313  	var res []error
   314  
   315  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   316  		res = append(res, err)
   317  	}
   318  
   319  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   320  		res = append(res, err)
   321  	}
   322  
   323  	if err := m.contextValidateID(ctx, formats); err != nil {
   324  		res = append(res, err)
   325  	}
   326  
   327  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   328  		res = append(res, err)
   329  	}
   330  
   331  	if err := m.contextValidateTags(ctx, formats); err != nil {
   332  		res = append(res, err)
   333  	}
   334  
   335  	if err := m.contextValidateURL(ctx, formats); err != nil {
   336  		res = append(res, err)
   337  	}
   338  
   339  	if len(res) > 0 {
   340  		return errors.CompositeValidationError(res...)
   341  	}
   342  	return nil
   343  }
   344  
   345  func (m *WritableService) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   346  
   347  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   348  		return err
   349  	}
   350  
   351  	return nil
   352  }
   353  
   354  func (m *WritableService) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   355  
   356  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   357  		return err
   358  	}
   359  
   360  	return nil
   361  }
   362  
   363  func (m *WritableService) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   364  
   365  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   366  		return err
   367  	}
   368  
   369  	return nil
   370  }
   371  
   372  func (m *WritableService) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   373  
   374  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   375  		return err
   376  	}
   377  
   378  	return nil
   379  }
   380  
   381  func (m *WritableService) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   382  
   383  	for i := 0; i < len(m.Tags); i++ {
   384  
   385  		if m.Tags[i] != nil {
   386  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   387  				if ve, ok := err.(*errors.Validation); ok {
   388  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   389  				} else if ce, ok := err.(*errors.CompositeError); ok {
   390  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   391  				}
   392  				return err
   393  			}
   394  		}
   395  
   396  	}
   397  
   398  	return nil
   399  }
   400  
   401  func (m *WritableService) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   402  
   403  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   404  		return err
   405  	}
   406  
   407  	return nil
   408  }
   409  
   410  // MarshalBinary interface implementation
   411  func (m *WritableService) MarshalBinary() ([]byte, error) {
   412  	if m == nil {
   413  		return nil, nil
   414  	}
   415  	return swag.WriteJSON(m)
   416  }
   417  
   418  // UnmarshalBinary interface implementation
   419  func (m *WritableService) UnmarshalBinary(b []byte) error {
   420  	var res WritableService
   421  	if err := swag.ReadJSON(b, &res); err != nil {
   422  		return err
   423  	}
   424  	*m = res
   425  	return nil
   426  }