blob: fc4ea39cf34742a042272b6fa18c6045e80efbdf [file] [log] [blame]
Serge Bazanskicc25bdf2018-10-25 14:02:58 +02001// Code generated by go-swagger; DO NOT EDIT.
2
3// Copyright 2018 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
17package models
18
19// This file was generated by the swagger tool.
20// Editing this file might prove futile when you re-run the swagger generate command
21
22import (
23 "encoding/json"
24
25 strfmt "github.com/go-openapi/strfmt"
26
27 "github.com/go-openapi/errors"
28 "github.com/go-openapi/swag"
29 "github.com/go-openapi/validate"
30)
31
32// WritableService writable service
33// swagger:model WritableService
34type WritableService struct {
35
36 // Created
37 // Read Only: true
38 Created strfmt.Date `json:"created,omitempty"`
39
40 // Description
41 // Max Length: 100
42 Description string `json:"description,omitempty"`
43
44 // Device
45 Device int64 `json:"device,omitempty"`
46
47 // ID
48 // Read Only: true
49 ID int64 `json:"id,omitempty"`
50
51 // ipaddresses
52 // Unique: true
53 Ipaddresses []int64 `json:"ipaddresses"`
54
55 // Last updated
56 // Read Only: true
57 LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
58
59 // Name
60 // Required: true
61 // Max Length: 30
62 Name *string `json:"name"`
63
64 // Port number
65 // Required: true
66 // Maximum: 65535
67 // Minimum: 1
68 Port *int64 `json:"port"`
69
70 // Protocol
71 // Required: true
72 Protocol *int64 `json:"protocol"`
73
74 // Virtual machine
75 VirtualMachine int64 `json:"virtual_machine,omitempty"`
76}
77
78// Validate validates this writable service
79func (m *WritableService) Validate(formats strfmt.Registry) error {
80 var res []error
81
82 if err := m.validateDescription(formats); err != nil {
83 // prop
84 res = append(res, err)
85 }
86
87 if err := m.validateIpaddresses(formats); err != nil {
88 // prop
89 res = append(res, err)
90 }
91
92 if err := m.validateName(formats); err != nil {
93 // prop
94 res = append(res, err)
95 }
96
97 if err := m.validatePort(formats); err != nil {
98 // prop
99 res = append(res, err)
100 }
101
102 if err := m.validateProtocol(formats); err != nil {
103 // prop
104 res = append(res, err)
105 }
106
107 if len(res) > 0 {
108 return errors.CompositeValidationError(res...)
109 }
110 return nil
111}
112
113func (m *WritableService) validateDescription(formats strfmt.Registry) error {
114
115 if swag.IsZero(m.Description) { // not required
116 return nil
117 }
118
119 if err := validate.MaxLength("description", "body", string(m.Description), 100); err != nil {
120 return err
121 }
122
123 return nil
124}
125
126func (m *WritableService) validateIpaddresses(formats strfmt.Registry) error {
127
128 if swag.IsZero(m.Ipaddresses) { // not required
129 return nil
130 }
131
132 if err := validate.UniqueItems("ipaddresses", "body", m.Ipaddresses); err != nil {
133 return err
134 }
135
136 return nil
137}
138
139func (m *WritableService) validateName(formats strfmt.Registry) error {
140
141 if err := validate.Required("name", "body", m.Name); err != nil {
142 return err
143 }
144
145 if err := validate.MaxLength("name", "body", string(*m.Name), 30); err != nil {
146 return err
147 }
148
149 return nil
150}
151
152func (m *WritableService) validatePort(formats strfmt.Registry) error {
153
154 if err := validate.Required("port", "body", m.Port); err != nil {
155 return err
156 }
157
158 if err := validate.MinimumInt("port", "body", int64(*m.Port), 1, false); err != nil {
159 return err
160 }
161
162 if err := validate.MaximumInt("port", "body", int64(*m.Port), 65535, false); err != nil {
163 return err
164 }
165
166 return nil
167}
168
169var writableServiceTypeProtocolPropEnum []interface{}
170
171func init() {
172 var res []int64
173 if err := json.Unmarshal([]byte(`[6,17]`), &res); err != nil {
174 panic(err)
175 }
176 for _, v := range res {
177 writableServiceTypeProtocolPropEnum = append(writableServiceTypeProtocolPropEnum, v)
178 }
179}
180
181// prop value enum
182func (m *WritableService) validateProtocolEnum(path, location string, value int64) error {
183 if err := validate.Enum(path, location, value, writableServiceTypeProtocolPropEnum); err != nil {
184 return err
185 }
186 return nil
187}
188
189func (m *WritableService) validateProtocol(formats strfmt.Registry) error {
190
191 if err := validate.Required("protocol", "body", m.Protocol); err != nil {
192 return err
193 }
194
195 // value enum
196 if err := m.validateProtocolEnum("protocol", "body", *m.Protocol); err != nil {
197 return err
198 }
199
200 return nil
201}
202
203// MarshalBinary interface implementation
204func (m *WritableService) MarshalBinary() ([]byte, error) {
205 if m == nil {
206 return nil, nil
207 }
208 return swag.WriteJSON(m)
209}
210
211// UnmarshalBinary interface implementation
212func (m *WritableService) UnmarshalBinary(b []byte) error {
213 var res WritableService
214 if err := swag.ReadJSON(b, &res); err != nil {
215 return err
216 }
217 *m = res
218 return nil
219}